ok, this is what I want to draw: a shape composed of 2 lines and 2 arcs
the bezierVertex() seems to work, but as I mentioned, the curve is not strictly an arc based on ellipse:
- Shape[] shapes = new Shape[3];
- void setup(){
- size(300,300);
- smooth(8);
-
- float eh = 100;
- float ew = 200;
- PVector l = new PVector(100,200);
-
- shapes[2] = new Shape(eh, ew, 100.0, 100.0/3, l);
- }
- void draw(){
- background(255);
- strokeWeight(4);
- stroke(0);
- strokeCap(PROJECT);
- strokeJoin(MITER);
- fill(255,0,0);
- //shapes[2].c = color(0);
- shapes[2].draw();
-
- }
- class Shape{
- //----- variables ------
- float ellipseHeight;
- float ellipseWidth;
- float shapeWidth;
- float shapeHeight;
- PVector location;
-
- //----- constructor -----
- Shape(float eh, float ew, float sh, float sw, PVector l){
- ellipseHeight = eh;
- ellipseWidth = ew;
- shapeWidth = sw;
- shapeHeight = sh;
- PVector p = l.get();
- location = p;
- }
-
- //------ draw shape -----
- void draw(){
- beginShape();
- vertex(location.x, location.y);
- vertex(location.x, location.y-shapeHeight);
- float theY = (ellipseHeight/2) * sin(acos(shapeWidth/(ellipseWidth/2)));
- bezierVertex(location.x, location.y-shapeHeight, //1st control pt
- location.x+shapeWidth, location.y-shapeHeight, //2nd control pt
- location.x+shapeWidth, location.y-shapeHeight+theY //anchor pt
- );
- //arc(location.x, location.y-shapeHeight+theY, shapeWidth*2, theY*2, -PI/2,0);
- vertex(location.x+shapeWidth, location.y-shapeHeight+theY);
- vertex(location.x+shapeWidth, location.y+theY);
- //arc(location.x, location.y+theY, shapeWidth*2, theY*2, -PI/2,0);
- bezierVertex(location.x+shapeWidth, location.y+theY, //1st control pt
- location.x+shapeWidth, location.y, //2nd control pt
- location.x, location.y //anchor pt
- );
- endShape();
- }
- }
But I can't get it work by using arc() inside beginShape()+endShape()
- Shape[] shapes = new Shape[3];
- void setup(){
- size(300,300);
- smooth(8);
-
- float eh = 100;
- float ew = 200;
- PVector l = new PVector(100,200);
-
- shapes[2] = new Shape(eh, ew, 100.0, 100.0/3, l);
- }
- void draw(){
- background(255);
- strokeWeight(4);
- stroke(0);
- strokeCap(PROJECT);
- strokeJoin(MITER);
- fill(255,0,0);
- //shapes[2].c = color(0);
- shapes[2].draw();
-
- }
- class Shape{
- //----- variables ------
- float ellipseHeight;
- float ellipseWidth;
- float shapeWidth;
- float shapeHeight;
- PVector location;
-
- //----- constructor -----
- Shape(float eh, float ew, float sh, float sw, PVector l){
- ellipseHeight = eh;
- ellipseWidth = ew;
- shapeWidth = sw;
- shapeHeight = sh;
- PVector p = l.get();
- location = p;
- }
-
- //------ draw shape -----
- void draw(){
- beginShape();
- vertex(location.x, location.y);
- vertex(location.x, location.y-shapeHeight);
- float theY = (ellipseHeight/2) * sin(acos(shapeWidth/(ellipseWidth/2)));
- // bezierVertex(location.x, location.y-shapeHeight, //1st control pt
- // location.x+shapeWidth, location.y-shapeHeight, //2nd control pt
- // location.x+shapeWidth, location.y-shapeHeight+theY //anchor pt
- // );
- arc(location.x, location.y-shapeHeight+theY, shapeWidth*2, theY*2, -PI/2,0);
- vertex(location.x+shapeWidth, location.y-shapeHeight+theY);
- vertex(location.x+shapeWidth, location.y+theY);
- arc(location.x, location.y+theY, shapeWidth*2, theY*2, -PI/2,0);
- // bezierVertex(location.x+shapeWidth, location.y+theY, //1st control pt
- // location.x+shapeWidth, location.y, //2nd control pt
- // location.x, location.y //anchor pt
- // );
- endShape();
- }
- }
advices are appreciated! Thanks!