We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Why theese bezierVertex don´t make an egg
Page Index Toggle Pages: 1
Why theese bezierVertex don´t make an egg (Read 1432 times)
Why theese bezierVertex don´t make an egg
Mar 10th, 2009, 9:14pm
 
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);

Why theese bezierVertex don´t make an egg like this?

...

the four anchor points are at the positions like the four dots in the picture
Re: Why theese bezierVertex don´t make an egg
Reply #1 - Mar 10th, 2009, 10:54pm
 
Your previous attempt was better... Smiley
Perhaps your control points (not shown in your drawing) aren't correctly placed?

The best way to know is to visualize them:

fill(#0000FF);
ellipse(40, 20, 3, 3);
ellipse(20, 40, 3, 3);
ellipse(-40, -40, 3, 3);
ellipse(20, -80, 3, 3);
fill(#00FF00);
ellipse(40, -40, 3, 3);
ellipse(-20, 40, 3, 3);
ellipse(-40, 20, 3, 3);
ellipse(-20, -80, 3, 3);
fill(#FF0000);
ellipse(40, 0, 3, 3);
ellipse(0, 40, 3, 3);
ellipse(-40, 0, 3, 3);
ellipse(0, -80, 3, 3);

I see the order isn't consistent. Perhaps you should try and swap some control points.
Re: Why theese bezierVertex don´t make an egg
Reply #2 - Mar 11th, 2009, 8:09am
 
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... Smiley

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... Smiley
I let you re-order them.
Re: Why theese bezierVertex don´t make an egg
Reply #3 - Apr 17th, 2009, 12:12pm
 
PhiLho  wrote on Mar 11th, 2009, 8:09am:
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... Smiley

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... Smiley
I let you re-order them.


it does not show all points
Re: Why theese bezierVertex don´t make an egg
Reply #4 - Apr 17th, 2009, 12:28pm
 
I don't understand your remark. You have 12 points, I have 12 points. What is the problem?
Re: Why theese bezierVertex don´t make an egg
Reply #5 - Apr 17th, 2009, 12:53pm
 
PhiLho  wrote on Apr 17th, 2009, 12:28pm:
I don't understand your remark. You have 12 points, I have 12 points. What is the problem


in the sketch-running window i cannot see all four anchor points and all 8 controll points as Lines and points

    Vertex(0, -80);
   BezierVertex(40, 20, 10, 10, 10, 10);
   BezierVertex(20, 40, 20, 20, 20, 20);
   BezierVertex(-40, -40, 30, 30, 30, 30);
   BezierVertex(20, -80, 40, 40, 40, 40);


makes this

...
Re: Why theese bezierVertex don´t make an egg
Reply #6 - Apr 17th, 2009, 1:55pm
 
because its a weird shape you created. works fine when i test it.
btw great example Philho
Re: Why theese bezierVertex don´t make an egg
Reply #7 - Apr 17th, 2009, 2:48pm
 
Thanks Cedric.

Kite_Fan, you tell my code is wrong, and show a different code... Sad
Page Index Toggle Pages: 1