I try to draw a circle with vertex, but my result is very dirty.
I read a few article about that but I don’t find a solution ready to eat, so I coded something like I think possible to work but…so if anybody have suggestion !
http://spencermortensen.com/articles/bezier-circle/
/*
* DRAW CIRCLE
*/
PVector [] pts = new PVector[4];
PVector [] pts_a = new PVector[4];
PVector [] pts_b = new PVector[4];
void setup() {
size(400,400,P2D);
float radius = 100;
PVector offset = new PVector(width/2,height/2);
// normal position
pts[0] = new PVector(0,-1);
pts[1] = new PVector(1,0);
pts[2] = new PVector(0,1);
pts[3] = new PVector(-1,0);
// kappa
int n = pts.length;
float magic_number = (4./3.)*tan(PI/(2*n));
pts_a[0] = pts[0].copy().add(-magic_number,0);
pts_a[1] = pts[1].copy().add(0,-magic_number);
pts_a[2] = pts[2].copy().add(magic_number,0);
pts_a[3] = pts[3].copy().add(0,magic_number);
pts_b[0] = pts[0].copy().add(magic_number,0);
pts_b[1] = pts[1].copy().add(0,magic_number);
pts_b[2] = pts[2].copy().add(-magic_number,0);
pts_b[3] = pts[3].copy().add(0,-magic_number);
// finalize position
for(int i = 0 ; i < pts.length ; i++) {
pts[i].mult(radius).add(offset);
pts_a[i].mult(radius).add(offset);
pts_b[i].mult(radius).add(offset);
}
}
void draw() {
background(125);
fill(255);
stroke(0);
strokeWeight(1);
beginShape();
vertex(pts[0].x,pts[0].y);
bezierVertex(pts_a[0].x,pts_a[0].y,pts_b[0].x,pts_b[0].y,pts[0].x,pts[0].y);
bezierVertex(pts_a[1].x,pts_a[1].y,pts_b[1].x,pts_b[1].y,pts[1].x,pts[1].y);
bezierVertex(pts_a[2].x,pts_a[2].y,pts_b[2].x,pts_b[2].y,pts[2].x,pts[2].y);
bezierVertex(pts_a[3].x,pts_a[3].y,pts_b[3].x,pts_b[3].y,pts[3].x,pts[3].y);
endShape();
strokeWeight(10);
for(int i = 0 ; i < pts.length ; i++) {
stroke(255,0,0);
point(pts[i].x,pts[i].y);
stroke(0,255,0);
point(pts_a[i].x,pts_a[i].y);
stroke(0,255,0);
point(pts_b[i].x,pts_b[i].y);
}
}