Polyspiral: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) (→{{header|Perl 6}}: Add a second fully animated version) |
Thundergnat (talk | contribs) m (→SDL full animation: Add ability to "reverse" direction) |
||
Line 1,475: | Line 1,475: | ||
===SDL full animation=== |
===SDL full animation=== |
||
Uses the same basic algorithm but fully animated. Use the arrow keys to speed up / slow down the update speed. |
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. |
||
<lang perl6>use SDL2::Raw; |
<lang perl6>use SDL2::Raw; |
||
Line 1,508: | Line 1,508: | ||
my ($x1, $y1); |
my ($x1, $y1); |
||
my $sleep = 0.03; |
my $sleep = 0.03; |
||
my $dir = 1; |
|||
main: loop { |
main: loop { |
||
$angle = ($angle + .01/π) % τ; |
$angle = ($angle + $dir * .01/π) % τ; |
||
($x1, $y1) = $width div 2, $height div 2; |
($x1, $y1) = $width div 2, $height div 2; |
||
Line 1,520: | Line 1,521: | ||
if ARROW_KEYS(.scancode) -> $comm { |
if ARROW_KEYS(.scancode) -> $comm { |
||
given $comm { |
given $comm { |
||
when 'K_LEFT' { $ |
when 'K_LEFT' { $dir = -1 } |
||
when 'K_RIGHT' { $ |
when 'K_RIGHT' { $dir = 1 } |
||
when 'K_UP' { $sleep -= . |
when 'K_UP' { $sleep -= .01; $sleep = 0 if $sleep < 0 } |
||
when 'K_DOWN' { $sleep += . |
when 'K_DOWN' { $sleep += .01 } |
||
} |
} |
||
} |
} |
||
Line 1,559: | Line 1,560: | ||
} |
} |
||
( $r, $g, $b ).map: ((*+$m) * 255).Int |
( $r, $g, $b ).map: ((*+$m) * 255).Int |
||
⚫ | |||
} |
|||
⚫ | |||
=={{header|Phix}}== |
=={{header|Phix}}== |