Hello
I have a slight problem with a section of a larger program I am writing. I have distilled the section causing the issue which basically generates a radius and attempts to evenly distribute ellipses of a set diameter around it. (code below)
Although it largely works, often when drawing the circle it seems that it is not dividing the angles properly causing a gap between the last and first ellipse drawn. Am guessing this is to do with the way I am dividing then re-assembling the angles (leaving a remainder) but cannot work out how to correct it.
Hope this makes sense, any advice would be appreciated.
Thanks
- void setup() {
- size(800, 800);
- smooth();
- }
- void draw() {
- }
- void mouseReleased() {
- drawRing(mouseX, mouseY);
- }
- void drawRing(int cX, int cY) {
- background(140); //draw BG
- float r = random(100, 200); //radius of circle
- float circWid = 20.0; //width of ellipses
- float theta = circWid / r; //arc angle in radians
- //calculates number of dots that can be draw around circumference
- float numDots = int(radians(360.00)/theta);
- pushMatrix();
- translate(cX, cY);
- for (float p = 0; p < numDots; p++) {
- float myTheta = p*theta; //calculate current angle
- float x = r*cos(myTheta); //calculate xPos
- float y = r*sin(myTheta); //calculate yPos
- ellipse(x, y, circWid-2, circWid-2); //draw dot
- }
- popMatrix();
- }
1