X-Git-Url: http://git.itanic.dy.fi/?p=mandelbrot;a=blobdiff_plain;f=mandelbrot.c;fp=mandelbrot.c;h=35dc6c64b0405cd64ce4e0afa540a2201203bbf7;hp=ae05fbd50f9591edb9d2cda85785b062adc6d66a;hb=bb75ed1d012e139423d99e179d9680513273f9f8;hpb=10394fae32c1a947bc2e000003c87b41599571ea 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);