in reply to 2D coords circling outwards

You pick up a fortune cookie (t). 

You eat the fortune cookie. --more--

This cookie has a scrap of paper inside. --more--

The paper reads "You should investigate polar coordinates."

Replies are listed 'Best First'.
Re: (boo) Re: 2D coords circling outwards
by no_slogan (Deacon) on Jun 09, 2001 at 01:33 UTC
    That would be a great suggestion, except we that we seem to be constrained to integer coordinates.

    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.