Polyspiral: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (→SDL full animation: palette rotate) |
Thundergnat (talk | contribs) m (→SDL full animation: Add pause function) |
||
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 left / right arrow keys to reverse the "direction" of angle change. Press Space bar to toggle animation freeze / thaw.
<lang perl6>use SDL2::Raw;
Line 1,496:
my $event = SDL_Event.new;
enum
K_UP => 82,
K_DOWN => 81,
K_LEFT => 80,
K_RIGHT => 79,
K_SPACE => 44,
);
Line 1,509 ⟶ 1,510:
my $sleep = 0.03;
my $dir = 1;
my $incr = .01/π;
my $step = $incr;
main: loop {
$angle = ($angle + $dir *
($x1, $y1) = $width div 2, $height div 2;
Line 1,519 ⟶ 1,522:
when *.type == QUIT { last main }
when *.type == KEYDOWN {
if
given $comm {
when 'K_LEFT' { $dir = -1 }
Line 1,525 ⟶ 1,528:
when 'K_UP' { $sleep -= .01; $sleep = 0 if $sleep < 0 }
when 'K_DOWN' { $sleep += .01 }
when 'K_SPACE' { $step = $step ?? 0 !! $incr }
}
}
Line 1,538 ⟶ 1,542:
($x1, $y1) = $x2, $y2;
}
@rgb.=rotate;
SDL_RenderPresent($render);
|