+quit:
+ printf("\nExiting. Good bye!\n");
+ return 1;
+}
+
+static void loop(struct context *ctx)
+{
+ long double aspect_ratio;
+ long double x1, x2, y1, y2;
+ int last_zoom;
+
+ do {
+ aspect_ratio = ctx->screen->w / (long double)ctx->screen->h;
+ ctx->origo_x += ctx->motion_x / ctx->zoom / ctx->screen->w;
+ ctx->origo_y += ctx->motion_y / ctx->zoom / ctx->screen->h;
+ ctx->motion_x = ctx->motion_y = 0;
+
+ if (ctx->zooms != last_zoom) {
+ int dx, dy;
+
+ dx = ctx->mx - ctx->screen->w / 2;
+ dy = ctx->my - ctx->screen->h / 2;
+
+ if (ctx->zooms > last_zoom) {
+ ctx->zoom *= ZOOM_FACTOR;
+ ctx->origo_x += dx / ctx->zoom /
+ (long double) ctx->screen->w;
+ ctx->origo_y += dy / ctx->zoom /
+ (long double) ctx->screen->h;
+ } else {
+ ctx->origo_x -= dx / ctx->zoom /
+ (long double) ctx->screen->w;
+ ctx->origo_y -= dy / ctx->zoom /
+ (long double) ctx->screen->h;
+ ctx->zoom /= ZOOM_FACTOR;
+ }
+
+ last_zoom = ctx->zooms;
+ }
+
+ 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 (%LF, %LF)(%LF, %LF), zoom %d\n",
+ x1, y1, x2, y2, ctx->zooms);
+
+ draw_mandelbrot(ctx->screen, x1, x2, y1, y2);
+ } while (!read_events(ctx));