diff options
Diffstat (limited to 'graphics.c')
| -rw-r--r-- | graphics.c | 24 |
1 files changed, 22 insertions, 2 deletions
@@ -4,6 +4,7 @@ #define WINDOW_X 20 #define WINDOW_Y 20 +static void update(GState *state); static void event_handler(GState *state); static void destroy_state(GState *state); static void error_exit_state(GState *state, const char *msg); @@ -17,7 +18,7 @@ GState *graphics_init(GConf *conf) if (SDL_Init(SDL_INIT_VIDEO) < 0) error_exit("unable to init SDL"); state->window = SDL_CreateWindow(WINDOW_TITLE, WINDOW_X, WINDOW_Y, - conf->window_width, conf->window_height, 0); + WINDOW_W, WINDOW_H, 0); if (state->window == NULL) error_exit("unable to create window"); state->renderer = SDL_CreateRenderer(state->window, -1, 0); @@ -38,9 +39,28 @@ void graphics_run(GState *state) while (state->running) { event_handler(state); + update(state); + SDL_Delay(3); + } +} - SDL_Delay(10); +static void update(GState *state) +{ + SDL_SetRenderDrawColor(state->renderer, 155, 155, 155, 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); + } + } } + SDL_RenderPresent(state->renderer); } static void event_handler(GState *state) |
