I'd approach it something like this:
First, divide your space into cells (each one will hold one character position).
Next, decide the thickness of your line you use to draw the circle.
To draw the circle, I'd draw the outermost circle (the one associated with the "outside" of your line) then subtract out your inner circle.
Finally, any cell completely inside or outside of your circle is easy: it's blank. Any cell completely within the two circles is similarly easy: it's as dark as possible (#). The intermediate values would depend on how much of the cell lies outside of the line.
Since your picture is a simple circle, all you need to do is compute the percentage of area obscured by your circle (from 0 to 100%) and the assign the "color" (i.e. ' ', '.', '+', '*', '#') based on the percentage.
Something like:
- Build array and set to 0 everywhere
- For each row
- For each column
- If cell totally outside of outer circle, cell=0
- Otherwise if cell is totally inside the inner circle, cell=0
- Otherwise if cell is totally within the two circles, cell=100
- Otherwise:
- Compute fraction of cell within the outer circle
- Subtract fraction of cell within the inner circle
- Look up character to print for the cell, based on the value
- print the character
I hope this is helpful, but doing too much of your work for you.
...roboticus
When your only tool is a hammer, all problems look like your thumb.
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.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, 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, summary, 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?
See Writeup Formatting Tips and other pages linked from there for more info.