
//CUBIC BEZIER MOUSE CLICKS
int x0, x1, x2, x3, y0, y1, y2, y3;
int count = 0;
void setup()
{
size(300, 300);
}
void draw()
{
}
void mousePressed()
{
if(count%4 == 0) {
x0 = mouseX;
y0 = mouseY;
point(x0, y0);
}
else if(count%4 == 1) {
x1 = mouseX;
y1 = mouseY;
point(x1, y1);
}
else if(count%4 == 2) {
x2 = mouseX;
y2 = mouseY;
point(x2, y2);
}
else {
x3 = mouseX;
y3 = mouseY;
point(x3, y3);
cubic(x0, y0, x1, y1, x2, y2, x3, y3);
}
count++;
}
void cubic(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3)
{
float xB, yB;
for(float t = 0; t < 1; t += .001) {
xB = (1-t)*(1-t)*(1-t)*x0 + 3 *(1-t)*(1-t)*t*x1 + 3*(1-t)*t*t*x2 + t*t*t*x3;
yB = (1-t)*(1-t)*(1-t)*y0 + 3 *(1-t)*(1-t)*t*y1 + 3*(1-t)*t*t*y2 + t*t*t*y3;
point(xB, yB);
}
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment