We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have this code here where I create an array for x and y coordinates for a complex sine cosine function. I then use the beginShape function and create bezierVertexes for each x and y coordinate. The problem is that I don't know what the coordinates are going to be for each of the handles and it seems impossible to try and hardcode every single handle coordinate. Is there any sort of formula to determine what the handles are going to be for my function?
float[] x;
float[] y;
float amplitude = 75.0;
void setup()
{
size(1200,1200);
}
void draw()
{
x = new float[5000];
x[0]=0;
for(int i=1; i<x.length; i++)
{
x[i]=x[i-1]+PI;
}
y = new float[x.length];
translate(0,height/2);
beginShape();
vertex(0,0);
for(int j=0; j<x.length; j++)
{
y[j]=amplitude*pow(sin(.025*x[j]),3)*cos(.025*x[j]);
stroke(0);
strokeWeight(1);
noFill();
if(j==0)
{
vertex(x[j],y[j]);
}
else
{
bezierVertex(x[j-1],y[j-1],x[j],y[j],x[j],y[j]);
}
}
endShape();
}
Answers
Right now I just guessed and used j-1 for each of the handles, but I'm not sure if that's right or not. The graph that it created actually looks alright, but it's really jaggedy and pixelated, and that makes me think that I did something wrong with the handles.
Relevant: https://forum.processing.org/two/discussion/21355/fixed-make-bezier-curve-pass-through-control-points
Kf
https://forum.processing.org/two/discussion/8075/why-are-text-and-graphics-so-ugly-and-blocky
in short: clear the background between frames.
in long: use noLoop() if your image isn't interactive or animated. why draw something 60 times a second when it doesn't change?
this annoys me too. why use a bezier curve if you're not going to actually use a bezier curve?
@Scott06 -- if you need to take this approach then @prince_polka 's bezier2 function will help you compute the handles backwards from the path points -- although note the many warnings that this provides A solution (one of many), not THE solution -- and solutions may sometimes not be what you want. See my demo sketch from the thread @kfrajer already linked.