Jump to content

Marching squares: Difference between revisions

m
→‎{{header|Raku}}: insignificant changes
(added Raku programming solution)
m (→‎{{header|Raku}}: insignificant changes)
Line 339:
for ^width X ^height -> (\x,\y) {
unless data[y;x] == 0 {
my \($cx,$cy,$directions = ,$previous) = '';x, y;
myrepeat ($cx,$cy,$direction,$previous){ = x, y;
loop {
my $mask = 0;
for (0,0,1),(1,0,2),(0,1,4),(1,1,8) -> (\dx,\dy,\b) {
my ($mx,$my) = $cx+dx,$cy+dy;
$mask += b if so all ( $mx>1, $my>1, data[$my-1;$mx-1] != 0)
}
$direction =given do given $mask {
when * ∈ ( 1, 5, 13 ) { N }
when * ∈ ( 2, 3, 7 ) { E }
Line 354 ⟶ 353:
when * ∈ ( 6 ) { $previous == N ?? W !! E }
when * ∈ ( 9 ) { $previous == E ?? N !! S }
} {
given $direction { $directions ~= $previous = $_ ;
($cx,$cy) <<+=<< |(@dx[.value], @dy[.value]) }
$previous = $_ ;
}
($cx,$cy) <<+=<< |(@dx[.value], @dy[.value]) }
} until $cx==x and $cy==y ;
 
return last if $cx==x, and-y, $cy==y ; directions
}
return x, -y, directions
}
}
351

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.