Langton's ant: Difference between revisions
Content added Content deleted
m (Different category name) |
(→{{header|Perl 6}}: move the defined test into the switch; we really use a quarter of the output area, not 50%) |
||
Line 1,358: | Line 1,358: | ||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |
||
{{trans|Perl}} |
{{trans|Perl}} |
||
In this version we use 4-bits-per-char graphics to shrink the output |
In this version we use 4-bits-per-char graphics to shrink the output to a quarter the area of ASCII graphics. |
||
<lang perl6>my @vecs = [1,0,1], [0,-1,1], [-1,0,1], [0,1,1]; |
<lang perl6>my @vecs = [1,0,1], [0,-1,1], [-1,0,1], [0,1,1]; |
||
constant @blocky = ' ▘▝▀▖▌▞▛▗▚▐▜▄▙▟█'.comb; |
constant @blocky = ' ▘▝▀▖▌▞▛▗▚▐▜▄▙▟█'.comb; |
||
Line 1,365: | Line 1,365: | ||
my @plane = [White xx $size] xx $size; |
my @plane = [White xx $size] xx $size; |
||
my ($x, $y) = $size/2, $size/2; |
my ($x, $y) = $size/2, $size/2; |
||
my $dir = |
my $dir = @vecs.keys.pick; |
||
my $moves = 0; |
my $moves = 0; |
||
loop { |
loop { |
||
given |
given @plane[$x][$y] { |
||
when :!defined { last } |
|||
when White { $dir++; $_ = Black; } |
when White { $dir++; $_ = Black; } |
||
when Black { $dir--; $_ = White; } |
when Black { $dir--; $_ = White; } |