Skip to content

Commit

Permalink
Make autopilot mode cycle through the random targets forever.
Browse files Browse the repository at this point in the history
  • Loading branch information
ttsiodras committed Jan 15, 2021
1 parent 48926d5 commit 777db9a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 26 deletions.
7 changes: 5 additions & 2 deletions src/mandel.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,11 @@ int main(int argc, char *argv[])

init256(bSSE);

const char *usage =
"Left click to zoom-in, right-click to zoom-out, ESC to quit...";
const char *usage;
if (bAutoPilot)
usage = "ESC to quit...";
else
usage = "Left click to zoom-in, right-click to zoom-out, ESC to quit...";
SDL_WM_SetCaption(usage, usage);

if (bSSE)
Expand Down
63 changes: 39 additions & 24 deletions src/xaos.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,35 +240,50 @@ int autopilot()
};
const int total_interesting_points =
sizeof(interesting_points) / sizeof(interesting_points[0]);
int rand_idx = rand() % total_interesting_points;
double targetx = interesting_points[rand_idx][0];
double targety = interesting_points[rand_idx][1];
int start_idx = rand() % total_interesting_points;

int i = 0;
int x,y;
double xld = -2.2, yld=-1.1, xru=-2+(MAXX/MAXY)*3., yru=1.1;
while(1) {
// Where shall we zoom this time?
int rand_idx = start_idx % total_interesting_points;
double targetx = interesting_points[rand_idx][0];
double targety = interesting_points[rand_idx][1];
start_idx++;

// Re-initialize the window location...
double xld = -2.2, yld=-1.1, xru=-2+(MAXX/MAXY)*3., yru=1.1;

// Start by drawing everything...
double percentage_of_pixels = 100.0;

// Go!
while(1) {
unsigned st = SDL_GetTicks();
mandel(xld, yld, xru, yru, percentage_of_pixels);
unsigned en = SDL_GetTicks();

// After the 1st frame, re-use 99.25% of the pixels:
percentage_of_pixels = 0.75;

while(i<ZOOM_FRAMES) {
unsigned st = SDL_GetTicks();
mandel(xld, yld, xru, yru, 0.75); // Re-use 99.25% of the pixels.
unsigned en = SDL_GetTicks();
if (en - st < minimum_ms_per_frame)
// Limit frame rate to 60 fps.
SDL_Delay(minimum_ms_per_frame - en + st);
if (en - st < minimum_ms_per_frame)
SDL_Delay(minimum_ms_per_frame - en + st);

int result = kbhit(&x, &y);
if (result == 1)
break;
// Did we zoom too much?
double xrange = xru-xld;
if (xrange < ZOOM_LIMIT)
break;
xld += (targetx - xld)/100.;
xru += (targetx - xru)/100.;
yld += (targety - yld)/100.;
yru += (targety - yru)/100.;
i++;
int x,y;
int result = kbhit(&x, &y);
if (result == 1)
return i;
// Did we zoom too much?
double xrange = xru-xld;
if (xrange < ZOOM_LIMIT)
break;
xld += (targetx - xld)/100.;
xru += (targetx - xru)/100.;
yld += (targety - yld)/100.;
yru += (targety - yru)/100.;
i++;
}
}
return i;
}

int mousedriven()
Expand Down

0 comments on commit 777db9a

Please sign in to comment.