OK, after a good night sleep, I was able to write a helper to visualize the control points (my primitive attempt yesterday didn't show the lines, I couldn't see well the errors).
I made a little sketch based on your
other sketch and the fragment you show.
I added my functions wrapping vertex and bezierVertex, showing the relationships between them.
I used Bézier curves in a number of sketches (drawing a heart, for example) but I couldn't recall how to connect control points and anchor points, so this helper will be handy next time!
Although logical, these functions aren't the most intuitive of Processing...
Eggs.pde -
Code:Egg e1;
void setup()
{
size(400, 600);
smooth();
e1 = new Egg(66, 132, 66);
}
class Egg {
float x, y; // X-coordinate, y-coordinate
float angle; // Used to define the tilt
float scalar; // Height of the egg
// Constructor
Egg(int xpos, int ypos, float s) {
x = xpos;
y = ypos;
scalar = s / 100.0;
}
void display() {
noStroke();
fill(255, 150);
translate(x, y);
scale(scalar);
scale(3.0); translate(50, 50);
beginShape();
Vertex(0, -100);
BezierVertex(25, -100, 40, -65, 40, -40);
BezierVertex(40, -15, 25, 0, 0, 0);
BezierVertex(-25, 0, -40, -15, -40, -40);
BezierVertex(-40, -65, -25, -100, 0, -100);
endShape();
fill(255, 150);
translate(50, 120);
beginShape();
Vertex(0, -80);
BezierVertex(40, 20, 40, -40, 40, 0);
BezierVertex(20, 40, -20, 40, 0, 40);
BezierVertex(-40, -40, -40, 20, -40, 0);
BezierVertex(-20, -80, -20, -80, 0, -80);
endShape();
}
}
void draw()
{
background(0);
e1.display();
}
BezierHelper.pde -
Code:float BezierHelper_prevX = 0;
float BezierHelper_prevY = 0;
void Vertex(float x, float y)
{
pushStyle();
ellipseMode(CENTER);
noStroke();
// Reference point (if Bézier curve is drawn close of 0 and translated)
fill(#FF00FF, 200);
ellipse(0, 0, 5, 5);
// Starting point of the curve
fill(#FFFF00, 200);
ellipse(x, y, 5, 5);
popStyle();
BezierHelper_prevX = x;
BezierHelper_prevY = y;
vertex(x, y);
}
void BezierVertex(float cx1, float cy1, float cx2, float cy2, float x, float y)
{
pushStyle();
rectMode(CORNERS);
ellipseMode(CENTER);
// Anchor point
fill(#0000FF, 200);
noStroke();
rect(x-1, y-1, x+1, y+1);
// First control point
stroke(#00FF00, 220);
strokeWeight(1);
line(BezierHelper_prevX, BezierHelper_prevY, cx1, cy1);
fill(#00FF00, 200);
noStroke();
ellipse(cx1, cy1, 3, 3);
// Second control point
stroke(#FF0000, 220);
strokeWeight(1);
line(x, y, cx2, cy2);
fill(#FF0000, 200);
noStroke();
ellipse(cx2, cy2, 3, 3);
popStyle();
BezierHelper_prevX = x;
BezierHelper_prevY = y;
bezierVertex(cx1, cy1, cx2, cy2, x, y);
}
As you see, just use Vertex() instead of vertex() and BezierVertex() instead of bezierVertex().
You can see the order of your control points isn't right...
I let you re-order them.