Raster bars: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) (→{{header|Perl 6}}: add a screenshot) |
Thundergnat (talk | contribs) (→{{header|Perl 6}}: Rearrange, add a few more options, at this point I'm just fiddling with it.) |
||
Line 4: | Line 4: | ||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |
||
{{works with|Rakudo|2019.03}} |
{{works with|Rakudo|2019.03}} |
||
As there is no reference implementation, and rather sketchy task instructions, this may or may not fulfill the original authors intent. |
As there is no reference implementation, and rather sketchy task instructions, this may or may not fulfill the original task authors intent. |
||
Not really sure what is meant by "swaying". |
Not really sure what is meant by "swaying". |
||
Line 15: | Line 15: | ||
* Use Space bar to pause / resume scrolling. |
* Use Space bar to pause / resume scrolling. |
||
* Use Left Ctrl to reverse scroll direction. |
* Use Left Ctrl to reverse scroll direction. |
||
* Use Z / X to change the angle of the raster bars. |
|||
* Press Q to exit. |
|||
<lang perl6>use SDL2::Raw; |
<lang perl6>use SDL2::Raw; |
||
Line 46: | Line 48: | ||
K_PGDN => 78, |
K_PGDN => 78, |
||
K_LCTRL => 224, |
K_LCTRL => 224, |
||
⚫ | |||
⚫ | |||
⚫ | |||
); |
); |
||
my $dir = -1; |
my $dir = -1; |
||
my $step = 5; |
my $step = 5; |
||
my $incr = 1; |
my $incr = 1; |
||
my $gap = |
my $gap = 100; |
||
my $bh = 64; |
my $bh = 64; |
||
$height += 32; |
$height += 32; |
||
my $port = +@bars * $gap; |
my $port = +@bars * $gap; |
||
my $y = $dir > 0 ?? $height - $port !! $height; |
my $y = $dir > 0 ?? $height - $port !! $height; |
||
my $angle = 0; |
|||
main: loop { |
main: loop { |
||
while SDL_PollEvent($event) |
handle-event($event) while SDL_PollEvent($event); |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
$y = $step * $dir + $y; |
$y = $step * $dir + $y; |
||
if $dir > 0 { |
if $dir > 0 { |
||
$y = $height - $port if $y > 0 |
|||
} else { |
} else { |
||
if $y < $height - $port |
$y = 0 if $y < $height - $port |
||
} |
} |
||
for ^@bars { |
for ^@bars { |
||
my $ |
my $offset = $gap / cos(π * $angle / 180); |
||
SDL_RenderCopyEx( $render, @bars[$_], Nil, |
|||
SDL_Rect.new( -$gap, $y + $offset * $_, $width * 2, $bh), |
|||
$angle.Num, SDL_Point.new(:x(0),:y(0)), 0 |
|||
) |
|||
} |
} |
||
Line 109: | Line 93: | ||
given Cairo::Context.new($bar) { |
given Cairo::Context.new($bar) { |
||
my Cairo::Pattern::Gradient::Linear $lpat .= create(0.0, 0.0, 0.0, 32.0); |
my Cairo::Pattern::Gradient::Linear $lpat .= create(0.0, 0.0, 0.0, 32.0); |
||
$lpat.add_color_stop_rgba( 1, |(@color »*» .3), 1 |
$lpat.add_color_stop_rgba( 1, |(@color »*» .3), 1); |
||
$lpat.add_color_stop_rgba( .2, |(@color), 1 |
$lpat.add_color_stop_rgba( .2, |(@color), 1); |
||
$lpat.add_color_stop_rgba( .8, |(@color), 1 |
$lpat.add_color_stop_rgba( .8, |(@color), 1); |
||
$lpat.add_color_stop_rgba( 0, |(@color »+» .8), 1 |
$lpat.add_color_stop_rgba( 0, |(@color »+» .8), 1); |
||
.rectangle(0, 0, 1, 32); |
.rectangle(0, 0, 1, 32); |
||
.pattern($lpat); |
.pattern($lpat); |
||
Line 131: | Line 115: | ||
$bar_texture |
$bar_texture |
||
} |
|||
sub handle-event ($event) { |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
when 'K_Z' { $angle = $angle > -45 ?? $angle - 1 !! $angle } |
|||
when 'K_X' { $angle = $angle < 45 ?? $angle + 1 !! $angle } |
|||
when 'K_Q' { last main } |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
|||
} |
|||
⚫ | |||
}</lang> |
}</lang> |
||