go ahead... be a heretic PerlMonks

comment on

 Need Help??

Just for fun, here's a 2-step method that fills the inner square first and then conditionally computes a quadrant outside that but inside the outer square (and copies this to the other quadrants as it goes along). The inner square is the largest square that fits entirely inside the circle whereas the outer square is the smallest square that entirely encompasses the circle. It's not very Perlish and it doesn't do bounds checking which is why you can see part of the circle on the opposite side if you display the results.

```sub illuminate{
my \$centre_row = shift;
my \$centre_col = shift;
my \$insq       = int (\$radius / sqrt (2));
my @ans;

# inner square
for my \$i (\$centre_row - \$insq .. \$centre_row + \$insq) {
for my \$j (\$centre_col - \$insq .. \$centre_col + \$insq) {
push @ans, [\$i, \$j];
}
}

# outer square
for my \$i (0 .. \$radius) {
for my \$j (0 .. \$radius) {
next if \$i < \$insq and \$j < \$insq;
if (\$i * \$i + \$j * \$j < \$r2) {
push @ans,
[\$centre_row + \$i, \$centre_col + \$j],
[\$centre_row - \$i, \$centre_col + \$j],
[\$centre_row + \$i, \$centre_col - \$j],
[\$centre_row - \$i, \$centre_col - \$j];
}
}
}
return @ans;
}

(I changed the spelling of your variables since as a native speaker of British English it is almost impossible for me to type "center" consistently.)

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

• Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
• Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
• Read Where should I post X? if you're not absolutely sure you're posting in the right place.
• Posts may use any of the Perl Monks Approved HTML tags:
a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
• You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
 For: Use: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?

Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2020-08-14 08:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Which rocket would you take to Mars?

Results (75 votes). Check out past polls.

Notices?