Polyspiral: Difference between revisions

Content added Content deleted
(→‎{{header|Perl 6}}: Add a second fully animated version)
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' { $sleep += .001 }
when 'K_LEFT' { $dir = -1 }
when 'K_RIGHT' { $sleep -= .001 if $sleep > .001 }
when 'K_RIGHT' { $dir = 1 }
when 'K_UP' { $sleep -= .05; $sleep = 0 if $sleep < 0 }
when 'K_UP' { $sleep -= .01; $sleep = 0 if $sleep < 0 }
when 'K_DOWN' { $sleep += .05 }
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
}</lang>
}
</lang>


=={{header|Phix}}==
=={{header|Phix}}==