From 003e9e628b3e7b516d3d70d78b6ba97bca69c813 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 27 Aug 2019 19:19:59 +0200 Subject: Brightness level according to step before excusion The test to check if something is in the set return -1 else returns the number of steps, then map the step to a brightness of the pixel. --- graphics.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'graphics.c') diff --git a/graphics.c b/graphics.c index 1e7470f..e36fee0 100644 --- a/graphics.c +++ b/graphics.c @@ -46,18 +46,21 @@ void graphics_run(GState *state) static void update(GState *state) { - SDL_SetRenderDrawColor(state->renderer, 155, 155, 155, SDL_ALPHA_OPAQUE); + SDL_SetRenderDrawColor(state->renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); SDL_RenderClear(state->renderer); for (int x = 0; x < WINDOW_W; x++) { for (int y = 0; y < WINDOW_H; y++) { - if (mandelbrot_in_set(map_range((double)x, 0, WINDOW_W, LO, HI) - + map_range((double)y, 0, WINDOW_H, LO, HI) * I)) - { - SDL_SetRenderDrawColor(state->renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); - SDL_RenderDrawPoint(state->renderer, x, y); - } + double complex mapped_z = map_range((double)x, 0, WINDOW_W, LO, HI) + + map_range((double)y, 0, WINDOW_H, LO, HI) * I; + int steps = mandelbrot_in_set(mapped_z); + if (steps == -1) + continue; + double brightness = map_range(steps, LO, HI, 0, 20); + SDL_SetRenderDrawColor(state->renderer, brightness, brightness, + brightness, SDL_ALPHA_OPAQUE); + SDL_RenderDrawPoint(state->renderer, x, y); } } SDL_RenderPresent(state->renderer); -- cgit