in reply to (boo) Re: 2D coords circling outwards
in thread 2D coords circling outwards
I can't think of any way to avoid dealing with the four sides of the square separately. You might try replacing the range loop body with something like the fragment below. I think it's somewhat easier to understand, and it doesn't print each corner of the square twice (though it does miss the origin).
my ($x, $y) = ($range, $range); while ($x > -$range) { print "$x,$y\n"; $x-- } while ($y > -$range) { print "$x,$y\n"; $y-- } while ($x < $range) { print "$x,$y\n"; $x++ } while ($y < $range) { print "$x,$y\n"; $y++ }
This shows why it's nice that perl lets you do what you want with whitespace, unlike some other languages.
|
|---|