Jump to content

Polyspiral: Difference between revisions

→‎SDL full animation: Add some more control options, make update speed not dependant on sleep. I'm just playing at this point.
m (→‎SDL full animation: Add pause function)
(→‎SDL full animation: Add some more control options, make update speed not dependant on sleep. I'm just playing at this point.)
Line 1,475:
 
===SDL full animation===
Uses the same basic algorithm but fully animated. Use the up / down arrow keys to speed up / slow down the update speed. Use PgUp / PgDn keys to increment / decrement animation speed by large amounts. Use left / right arrow keys to reverse the "direction" of angle change. Press Space bar to toggle animation freeze / thawreset to minimum speed.
 
<lang perl6>use SDL2::Raw;
Line 1,502:
K_RIGHT => 79,
K_SPACE => 44,
K_PGUP => 75,
K_PGDN => 78,
);
 
Line 1,508 ⟶ 1,510:
my @rgb = (^$lines).map: { hsv2rgb(($_ * 360/$lines % 360)/360, 1, 1).list };
my ($x1, $y1);
my $sleep = 0.03;
my $dir = 1;
my $incr = .010001/π;
my $step = $incr*100;
 
main: loop {
Line 1,526 ⟶ 1,527:
when 'K_LEFT' { $dir = -1 }
when 'K_RIGHT' { $dir = 1 }
when 'K_UP' { $sleepstep -+= .01; $sleep = 0 if $sleep < 0incr }
when 'K_DOWN' { if $sleepstep +> 2*$incr { $step -= .01$incr } }
when 'K_PGUP' { $step += $incr*50 }
when 'K_PGDN' { $step -= $incr*50; $step = $step < $incr ?? $incr !! $step }
when 'K_SPACE' { $step = $step ?? 0 !! $incr }
}
Line 1,544 ⟶ 1,547:
@rgb.=rotate;
SDL_RenderPresent($render);
sleep($sleep);
SDL_SetRenderDrawColor($render, 0, 0, 0, 0);
SDL_RenderClear($render);
10,333

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.