Skip to content
Snippets Groups Projects
Verified Commit 93def587 authored by orestis.malaspin's avatar orestis.malaspin
Browse files

updated to take into account shift and renorm

parent 0bd042e5
No related branches found
No related tags found
No related merge requests found
Pipeline #14682 passed
...@@ -7,34 +7,30 @@ ...@@ -7,34 +7,30 @@
#define SCREEN_WIDTH 1280 #define SCREEN_WIDTH 1280
#define SCREEN_HEIGHT 720 #define SCREEN_HEIGHT 720
double rand_dbl() double rand_dbl() {
{ return 2.0 * ((double)rand()) / RAND_MAX - 0.5;
return ((double)rand()) / RAND_MAX;
} }
int main() int main() {
{
srand(time(NULL)); srand(time(NULL));
struct gfx_context_t *ctxt = struct gfx_context_t *ctxt =
gfx_create("Vec2 demo", SCREEN_WIDTH, SCREEN_HEIGHT); gfx_create("Vec2 demo", SCREEN_WIDTH, SCREEN_HEIGHT);
if (!ctxt) if (!ctxt) {
{
fprintf(stderr, "Graphics initialization failed!\n"); fprintf(stderr, "Graphics initialization failed!\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
vec2 center = vec2_create(0.5, 0.5); vec2 center = vec2_create(0.0, 0.0);
double radius = 0.5; double radius = 0.5;
for (int i = 0; i < 250000; i++) for (int i = 0; i < 250000; i++) {
{
vec2 r = vec2_create(rand_dbl(), rand_dbl()); vec2 r = vec2_create(rand_dbl(), rand_dbl());
//Draw pixel if in circle // Draw pixel if in circle
if (vec2_norm(vec2_sub(r, center)) < radius) if (vec2_norm(vec2_sub(r, center)) < radius) {
{ coordinates pixel =
coordinates pixel = vec2_to_coordinates(r, SCREEN_WIDTH, SCREEN_HEIGHT); vec2_to_coordinates(r, SCREEN_WIDTH, SCREEN_HEIGHT);
//Random color (not black) // Random color (not black)
uint32_t color = rand() % 0xFFFFFF; uint32_t color = rand() % 0xFFFFFF;
gfx_putpixel(ctxt, pixel.column, pixel.row, color); gfx_putpixel(ctxt, pixel.column, pixel.row, color);
...@@ -42,13 +38,11 @@ int main() ...@@ -42,13 +38,11 @@ int main()
} }
gfx_present(ctxt); gfx_present(ctxt);
while (true) while (true) {
{ if (gfx_keypressed() == SDLK_ESCAPE) {
if (gfx_keypressed() == SDLK_ESCAPE)
{
break; break;
} }
} }
gfx_destroy(ctxt); gfx_destroy(ctxt);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment