Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
struct context {
struct SDL_Surface *screen;
struct context {
struct SDL_Surface *screen;
- double origo_x, origo_y;
+ long double origo_x, origo_y;
};
static void putpixel(struct SDL_Surface *screen, const int x, const int y,
};
static void putpixel(struct SDL_Surface *screen, const int x, const int y,
#define MAX_ITERATION 1000
#define MAX_ITERATION 1000
-int get_mandelbrot_iterations(double x0, double y0)
+int get_mandelbrot_iterations(long double x0, long double y0)
- double x = 0, y = 0, xtemp;
+ long double x = 0, y = 0, xtemp;
int iteration = 0;
while ((x * x + y * y < 2 * 2) && iteration < MAX_ITERATION) {
int iteration = 0;
while ((x * x + y * y < 2 * 2) && iteration < MAX_ITERATION) {
-int draw_mandelbrot(struct SDL_Surface *screen, double x1, double x2,
- double y1, double y2)
+int draw_mandelbrot(struct SDL_Surface *screen, long double x1, long double x2,
+ long double y1, long double y2)
- double x0, y0, xlen, ylen, xstep, ystep;
+ long double x0, y0, xlen, ylen, xstep, ystep;
int iteration, xs, ys;
xlen = x2 - x1;
ylen = y2 - y1;
int iteration, xs, ys;
xlen = x2 - x1;
ylen = y2 - y1;
- xstep = xlen / (double)screen->w;
- ystep = ylen / (double)screen->h;
+ xstep = xlen / (long double)screen->w;
+ ystep = ylen / (long double)screen->h;
y0 = y1;
#pragma omp parallel for private(xs, ys, x0, y0)
y0 = y1;
#pragma omp parallel for private(xs, ys, x0, y0)
case SDL_MOUSEBUTTONDOWN:
if (event.button.button == 4) {
ctx->zoom *= 1.5;
case SDL_MOUSEBUTTONDOWN:
if (event.button.button == 4) {
ctx->zoom *= 1.5;
+ ctx->zooms++;
+ delayed_exit++;
} else if (event.button.button == 5) {
ctx->zoom /= 1.5;
} else if (event.button.button == 5) {
ctx->zoom /= 1.5;
delayed_exit++;
} else {
ctx->scroll_enabled = 1;
delayed_exit++;
} else {
ctx->scroll_enabled = 1;
static void loop(struct context *ctx)
{
static void loop(struct context *ctx)
{
+ long double aspect_ratio;
+ long double x1, x2, y1, y2;
do {
aspect_ratio = ctx->screen->w / ctx->screen->h;
do {
aspect_ratio = ctx->screen->w / ctx->screen->h;
ctx->origo_y += ctx->motion_y / ctx->zoom / ctx->screen->h;
ctx->motion_x = ctx->motion_y = 0;
ctx->origo_y += ctx->motion_y / ctx->zoom / ctx->screen->h;
ctx->motion_x = ctx->motion_y = 0;
- draw_mandelbrot(ctx->screen,
- ctx->origo_x - aspect_ratio / ctx->zoom,
- ctx->origo_x + aspect_ratio / ctx->zoom,
- ctx->origo_y - 1 / ctx->zoom,
- ctx->origo_y + 1 / ctx->zoom);
+ x1 = ctx->origo_x - aspect_ratio / ctx->zoom;
+ x2 = ctx->origo_x + aspect_ratio / ctx->zoom;
+ y1 = ctx->origo_y - 1 / ctx->zoom;
+ y2 = ctx->origo_y + 1 / ctx->zoom;
printf("Drawing area (%f, %f)(%f, %f), zoom %d\n",
printf("Drawing area (%f, %f)(%f, %f), zoom %d\n",
- x1, y1, x2, y2, ctx->zoom );
+ x1, y1, x2, y2, ctx->zooms);
+ draw_mandelbrot(ctx->screen, x1, x2, y1, y2);
} while (!read_events(ctx));
}
} while (!read_events(ctx));
}