Polyspiral: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (→SDL full animation: Add pause function) |
Thundergnat (talk | contribs) (→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: | Line 1,475: | ||
===SDL full animation=== |
===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 |
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 / reset to minimum speed. |
||
<lang perl6>use SDL2::Raw; |
<lang perl6>use SDL2::Raw; |
||
Line 1,502: | Line 1,502: | ||
K_RIGHT => 79, |
K_RIGHT => 79, |
||
K_SPACE => 44, |
K_SPACE => 44, |
||
K_PGUP => 75, |
|||
K_PGDN => 78, |
|||
); |
); |
||
Line 1,508: | Line 1,510: | ||
my @rgb = (^$lines).map: { hsv2rgb(($_ * 360/$lines % 360)/360, 1, 1).list }; |
my @rgb = (^$lines).map: { hsv2rgb(($_ * 360/$lines % 360)/360, 1, 1).list }; |
||
my ($x1, $y1); |
my ($x1, $y1); |
||
my $sleep = 0.03; |
|||
my $dir = 1; |
my $dir = 1; |
||
my $incr = . |
my $incr = .0001/π; |
||
my $step = $incr; |
my $step = $incr*100; |
||
main: loop { |
main: loop { |
||
Line 1,526: | Line 1,527: | ||
when 'K_LEFT' { $dir = -1 } |
when 'K_LEFT' { $dir = -1 } |
||
when 'K_RIGHT' { $dir = 1 } |
when 'K_RIGHT' { $dir = 1 } |
||
when 'K_UP' { $ |
when 'K_UP' { $step += $incr } |
||
when 'K_DOWN' { $ |
when 'K_DOWN' { if $step > 2*$incr { $step -= $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 } |
when 'K_SPACE' { $step = $step ?? 0 !! $incr } |
||
} |
} |
||
Line 1,544: | Line 1,547: | ||
@rgb.=rotate; |
@rgb.=rotate; |
||
SDL_RenderPresent($render); |
SDL_RenderPresent($render); |
||
sleep($sleep); |
|||
SDL_SetRenderDrawColor($render, 0, 0, 0, 0); |
SDL_SetRenderDrawColor($render, 0, 0, 0, 0); |
||
SDL_RenderClear($render); |
SDL_RenderClear($render); |