Marching squares: Difference between revisions

Content added Content deleted
m (→‎{{header|Raku}}: insignificant changes)
m (→‎{{header|Raku}}: small simplifications)
Line 338: Line 338:


for ^width X ^height -> (\x,\y) {
for ^width X ^height -> (\x,\y) {
unless data[y;x] == 0 {
if data[y;x] {
my ($cx,$cy,$directions,$previous) = x, y;
my ($cx,$cy,$directions,$previous) = x, y;
repeat {
repeat {
my $mask = 0;
my $mask;
for (0,0,1),(1,0,2),(0,1,4),(1,1,8) -> (\dx,\dy,\b) {
for (0,0,1),(1,0,2),(0,1,4),(1,1,8) -> (\dx,\dy,\b) {
my ($mx,$my) = $cx+dx,$cy+dy;
my ($mx,$my) = $cx+dx,$cy+dy;
$mask += b if so all $mx>1, $my>1, data[$my-1;$mx-1] != 0
$mask += b if all $mx>1, $my>1, data[$my-1;$mx-1]
}
}
given do given $mask {
given do given $mask {
Line 355: Line 355:
} {
} {
$directions ~= $previous = $_ ;
$directions ~= $previous = $_ ;
($cx,$cy) <<+=<< |(@dx[.value], @dy[.value])
($cx,$cy) <<+=<< (@dx[.value], @dy[.value])
}
}
} until $cx==x and $cy==y ;
} until $cx==x and $cy==y ;