From bb75ed1d012e139423d99e179d9680513273f9f8 Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Sun, 1 May 2011 19:10:38 +0300 Subject: [PATCH] Take drawing area as an parameter Signed-off-by: Timo Kokkonen --- mandelbrot.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/mandelbrot.c b/mandelbrot.c index ae05fbd..35dc6c6 100644 --- a/mandelbrot.c +++ b/mandelbrot.c @@ -34,16 +34,19 @@ int get_mandelbrot_iterations(double x0, double y0) return iteration; } -int draw_mandelbrot(struct SDL_Surface *screen) +int draw_mandelbrot(struct SDL_Surface *screen, double x1, double x2, + double y1, double y2) { - double x0, y0; - int iteration, xs,ys; + double x0, y0, xlen, ylen, xstep, ystep; + int iteration, xs, ys; - for (ys = 0, y0 = -1; ys < screen->h; - y0 += 2 / (double)screen->h, ys++) { - for (xs = 0, x0 = -2.5; xs < screen->w; - x0 += 3 / (double)screen->w, xs++) { + xlen = x2 - x1; + ylen = y2 - y1; + xstep = xlen / (double)screen->w; + ystep = ylen / (double)screen->h; + for (ys = 0, y0 = y1; ys < screen->h; y0 += ystep, ys++) { + for (xs = 0, x0 = x1; xs < screen->w; x0 += xstep, xs++) { iteration = get_mandelbrot_iterations(x0, y0); if (iteration == MAX_ITERATION) @@ -52,6 +55,7 @@ int draw_mandelbrot(struct SDL_Surface *screen) putpixel(screen, xs, ys, iteration, 0, 0); } + SDL_Flip(screen); } @@ -81,7 +85,7 @@ int main(int argc, char *argv[]) SDL_WM_SetCaption(argv[0], NULL); - draw_mandelbrot(screen); + draw_mandelbrot(screen, -2.5, 1, -1, 1); yres = read(0, &xres, 1); -- 2.44.0