gregor42 has asked for the wisdom of the Perl Monks concerning the following question:
I have been playing around with coordinate systems for a simple RPG. What I'm trying to do is to spit out a series of coordinates, starting from a center point (0,0) & circling outwards.
I have come up with this. But there's a lot of redundancy in the code. I know there is a simpler way to do this. Please bretheren, I ask your advice.
#!E:\perl\bin\perl.exe $max_range = 3; for $range(0..$max_range) { $y = $range; for $x(-$range..$range) { print "$x,$y \n"; } $x = $range; for $y(reverse(-$range..$range)) { print "$x,$y \n"; } $y = -($range); for $x(reverse(-$range..$range)) { print "$x,$y \n"; } $x = -$range; for $y(-$range..$range) { print "$x,$y \n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(boo) Re: 2D coords circling outwards
by boo_radley (Parson) on Jun 09, 2001 at 00:44 UTC | |
by no_slogan (Deacon) on Jun 09, 2001 at 01:33 UTC | |
|
Re: 2D coords circling outwards
by Albannach (Monsignor) on Jun 09, 2001 at 09:30 UTC | |
|
Re: 2D coords circling outwards
by bikeNomad (Priest) on Jun 09, 2001 at 21:37 UTC |