Drawing a circle with divisions
in
Programming Questions
•
1 year ago
Hi.
I have coded this function that allows you to draw a circle centered at (centerX, centerY) with a determined number of equal divisions.
My problem is that the rendering for divisions numbers not that hight (16+) start to get
a strange rendering effect at the center. I am already using smooth(). Any idea how to improve this? Thanks.
Here are some examples:
divisions = 16
divisions = 50
This is the whole code for the sketch:
- void setup() {
- size(500, 500);
- background(255);
- smooth();
- stroke(123);
- drawCircle(200, 200, 200, 12);
- }
- void drawCircle(int radius, int centerX, int centerY, int divisions) {
- ellipse(centerX, centerY, radius, radius);
- float rad = 0;
- for (int i = 0; i < divisions; i++) {
- rad += 2*PI / divisions;
- int x = (int)(radius/2 * cos(rad));
- int y = (int)(radius/2 * sin(rad));
- line(centerX, centerY, x+centerX, y+centerY);
- }
- }
1