From 93def587411331e5b1baf0c63eef8416ec19777c Mon Sep 17 00:00:00 2001 From: Orestis <orestis.malaspinas@pm.me> Date: Mon, 11 Oct 2021 14:13:10 +0200 Subject: [PATCH] updated to take into account shift and renorm --- practical_work/tp_vec2/main.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/practical_work/tp_vec2/main.c b/practical_work/tp_vec2/main.c index ac27974..7bee38f 100644 --- a/practical_work/tp_vec2/main.c +++ b/practical_work/tp_vec2/main.c @@ -7,34 +7,30 @@ #define SCREEN_WIDTH 1280 #define SCREEN_HEIGHT 720 -double rand_dbl() -{ - return ((double)rand()) / RAND_MAX; +double rand_dbl() { + return 2.0 * ((double)rand()) / RAND_MAX - 0.5; } -int main() -{ +int main() { srand(time(NULL)); struct gfx_context_t *ctxt = gfx_create("Vec2 demo", SCREEN_WIDTH, SCREEN_HEIGHT); - if (!ctxt) - { + if (!ctxt) { fprintf(stderr, "Graphics initialization failed!\n"); return EXIT_FAILURE; } - vec2 center = vec2_create(0.5, 0.5); + vec2 center = vec2_create(0.0, 0.0); 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()); - //Draw pixel if in circle - if (vec2_norm(vec2_sub(r, center)) < radius) - { - coordinates pixel = vec2_to_coordinates(r, SCREEN_WIDTH, SCREEN_HEIGHT); - //Random color (not black) + // Draw pixel if in circle + if (vec2_norm(vec2_sub(r, center)) < radius) { + coordinates pixel = + vec2_to_coordinates(r, SCREEN_WIDTH, SCREEN_HEIGHT); + // Random color (not black) uint32_t color = rand() % 0xFFFFFF; gfx_putpixel(ctxt, pixel.column, pixel.row, color); @@ -42,13 +38,11 @@ int main() } gfx_present(ctxt); - while (true) - { - if (gfx_keypressed() == SDLK_ESCAPE) - { + while (true) { + if (gfx_keypressed() == SDLK_ESCAPE) { break; } } gfx_destroy(ctxt); return EXIT_SUCCESS; -} \ No newline at end of file +} -- GitLab