So I have been trying to develop a separate application that relies heavy on the generation of pixel-by-pixel generation of circles and ellipses. However, do note 1) I am doing this app in Python, not Processing and 2) I am actually not so interested displaying a circle on the screen, but rather making a List/Stack of the (x,y) points that comprise that circle.
I’ve already tried out a number of the standard algorithms like Mid-Point and Bresenham’s (and even non-standard ones), and yes, they do produce a fine circle, but the particular way I am using them-- It is just not adding up right.
However, if I just ‘demo’ that same functionality in Processing, there is no problem.
In any case, seeing as Processing is open source, I just want to take a peak at the circle() and arc() functions.
I tried poking around the Processing V4 Github… But I can’t seem to find exactly where these functions reside (i.e. directory / file), or more importantly the calculations used.
The Processing code is unlikely to have what you’re looking for because it uses Java or OpenGL to do the actual rasterization of the geometry.
What is it about mid-point or Bresenham’s algorithms that doesn’t work for what you need? They can be tweaked to provide thick-edged, thin-edged, anti-aliased, or arbitrarily-centered circles. What’s the particular way that you want to use them?
I wrote a simple function creating the points of a ellipse. (I’m not that good in Python so I wrote it in Processing instead) but you should be able to adapt it:
The idea behind this code is using that the plot of the function sqrt(1-x^2) is basically a half circle. Now the two radi are used to stretch this circle.
Also to make the graph more consistent I used the derivative to estimate how big of a step I should make to not make it look like the ellipse has a hole.