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)
putpixel(screen, xs, ys,
iteration, 0, 0);
}
+
SDL_Flip(screen);
}
SDL_WM_SetCaption(argv[0], NULL);
- draw_mandelbrot(screen);
+ draw_mandelbrot(screen, -2.5, 1, -1, 1);
yres = read(0, &xres, 1);