From f7884d1aec1c803149a63d2811d767704d62ce77 Mon Sep 17 00:00:00 2001 From: Charles Date: Wed, 28 Aug 2019 09:18:20 +0200 Subject: Added primitive zoom with 'p'/'m' and moving with the arrow keys --- graphics.c | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/graphics.c b/graphics.c index dd146d2..4d29d2f 100644 --- a/graphics.c +++ b/graphics.c @@ -6,12 +6,14 @@ #define WINDOW_TITLE "Mandelbrot" #define WINDOW_X 20 #define WINDOW_Y 20 -#define WINDOW_W 500 -#define WINDOW_H 500 +#define WINDOW_W 300 +#define WINDOW_H 300 #define REFRESH_RATE 3 +#define MOVE_SIZE 0.1 +#define ZOOM_SIZE 0.1 #define BRIGHTNESS_LO 0 -#define BRIGHTNESS_HI 20 +#define BRIGHTNESS_HI 10 static void update(GState *state); static void event_handler(GState *state); @@ -94,6 +96,38 @@ static void event_handler(GState *state) case SDL_QUIT: state->running = false; break; + case SDL_KEYUP: + switch (e.key.keysym.sym) + { + case SDLK_UP: + state->imag_lo -= MOVE_SIZE; + state->imag_hi -= MOVE_SIZE; + break; + case SDLK_DOWN: + state->imag_lo += MOVE_SIZE; + state->imag_hi += MOVE_SIZE; + break; + case SDLK_LEFT: + state->real_lo -= MOVE_SIZE; + state->real_hi -= MOVE_SIZE; + break; + case SDLK_RIGHT: + state->real_lo += MOVE_SIZE; + state->real_hi += MOVE_SIZE; + break; + case SDLK_p: + state->real_lo += ZOOM_SIZE; + state->real_hi -= ZOOM_SIZE; + state->imag_lo += ZOOM_SIZE; + state->imag_hi -= ZOOM_SIZE; + break; + case SDLK_m: + state->real_lo -= ZOOM_SIZE; + state->real_hi += ZOOM_SIZE; + state->imag_lo -= ZOOM_SIZE; + state->imag_hi += ZOOM_SIZE; + break; + } } } } -- cgit