diff options
| author | Charles <sircharlesaze@gmail.com> | 2019-08-29 11:04:35 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2019-08-29 11:04:35 +0200 |
| commit | f85dda2684d7f75c77e3a78282dae89bc1f5a113 (patch) | |
| tree | 70a764b14a34cc7aeccb2e5bcc8b3db09e487946 /graphics.c | |
| parent | ec7cec7303aa642d234f444208a044dcc87904a4 (diff) | |
| download | mandelbrot-f85dda2684d7f75c77e3a78282dae89bc1f5a113.tar.gz mandelbrot-f85dda2684d7f75c77e3a78282dae89bc1f5a113.tar.bz2 mandelbrot-f85dda2684d7f75c77e3a78282dae89bc1f5a113.zip | |
Complex number optimization
Stop using the complex standard lib, replaced it with a variables
for the real part and imaginary part of z.
Diffstat (limited to 'graphics.c')
| -rw-r--r-- | graphics.c | 15 |
1 files changed, 9 insertions, 6 deletions
@@ -16,7 +16,7 @@ #define IMAG_LO(state) (state->center.y - state->imag_range / 2) #define IMAG_HI(state) (state->center.y + state->imag_range / 2) -#define IN_SET_COLOR 0x000000 +#define IN_SET_COLOR 0x050505 #define PALETTE_START 0x000022 #define PALETTE_END 0xd62f2f #define SET_DRAW_COLOR(renderer, c) ( \ @@ -24,7 +24,7 @@ static void update(GState *state); static void event_handler(GState *state); -static Color *create_palette(Color start, Color end); +/* static Color *create_palette(Color start, Color end); */ /* static void move_center(GState *state, int motion_x, int motion_y); */ static void recenter(GState *state, int x, int y); static void recenter_x(GState *state, int x); @@ -96,10 +96,13 @@ static void update(GState *state) { a = map_range((double)x, 0, state->window_w, REAL_LO(state), REAL_HI(state)); b = map_range((double)y, 0, state->window_h, IMAG_LO(state), IMAG_HI(state)); - int steps = mandelbrot_in_set(a + b * I); - if (steps == -1) + int frac_steps = mandelbrot_in_set(a, b); + if (frac_steps == -1) continue; - color = state->palette[steps]; + color = state->palette[frac_steps]; + /* color.rgb.r = 100 * frac_steps; */ + /* color.rgb.g = 100 * frac_steps; */ + /* color.rgb.b = 100 * frac_steps; */ SET_DRAW_COLOR(state->renderer, color); SDL_RenderDrawPoint(state->renderer, x, y); } @@ -180,7 +183,7 @@ static void event_handler(GState *state) } } -static Color *create_palette(Color start, Color end) + Color *create_palette(Color start, Color end) { int red_step = abs(end.rgb.r - start.rgb.r) / MAX_ITERATION; int green_step = abs(end.rgb.g - start.rgb.g) / MAX_ITERATION; |
