..
Perpetual Art landscapes nudes still life small collage travel galleries contact
corporate web folio code art iPad Apps T-Shirts work exp illustration digital games prints

******************

NERD ALERT!


An explanation of how I wrote the code for filling the shape of a circle.

******************
Coded Circles or "Spheres."


circle pic01
Additional Coded Circles or "Spheres."


circles 02


It was easy to fill a square or rectangle shape with little circles or "dots". The challenge was to write a program that would fill the shape of a circle. I started thinking about the concept of Polar Coordinates and began researching in that direction. Wow... my trigonometry class was way too many years ago. Most of my time was spent thinking about what is was that I was actually looking for...... which formula was the solution? I couldn't even remember the basic names of the parts I was needing to recall.

After much thinking and looking at Polar Coordinates, I came to the realization that I needed to simply use the Pythagorean Theorem,
a² + b² = c².

I knew I would assign the radius, and I knew I was going to write a loop that would take the x coordinate one pixel further on each iteration of the loop. That gave me the two requirments to find the third leg of a right triangle.

There is was! I had the hypotenuse, (the radius), and I had the cosine, (x coordinate). Now all I had to do was write the formula to calculate the y coordinate, (the sine), then find a random number between the y and x coordinates, and place the "dot" in that location. Sweet.

This formula does one quarter of the circle, so then I needed to fill the other quarters of the circle by using a couple of well placed negative numbers to make the loop work in the other directions on the x and y axis.

On the illustration below, I found a random coordinate on the "b" line, (the sine), to place the dots, starting at the center, and moving towards the edge of the circle one pixel at a time using the loop in the program. The other quadrants of the circle were filled by running the loop with negative numbers.

back to previous page


trig image