]> git.itanic.dy.fi Git - mandelbrot/commitdiff
Take drawing area as an parameter
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Sun, 1 May 2011 16:10:38 +0000 (19:10 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Sun, 1 May 2011 16:10:38 +0000 (19:10 +0300)
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
mandelbrot.c

index ae05fbd50f9591edb9d2cda85785b062adc6d66a..35dc6c64b0405cd64ce4e0afa540a2201203bbf7 100644 (file)
@@ -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);