Bitmap/Bézier curves/Cubic: Difference between revisions
Content added Content deleted
Line 1,092: | Line 1,092: | ||
It can be run on line [https://www.openprocessing.org/sketch/846556/ here.] |
It can be run on line [https://www.openprocessing.org/sketch/846556/ here.] |
||
<lang> |
<lang> |
||
int ptSize = 6; |
|||
float[]x = new float[4]; |
float[]x = new float[4]; |
||
float[]y = new float[4]; |
float[]y = new float[4]; |
||
Line 1,100: | Line 1,099: | ||
size(300, 300); |
size(300, 300); |
||
smooth(); |
smooth(); |
||
// |
// startpoint coordinates |
||
x[0] = x[1] = 50; |
x[0] = x[1] = 50; |
||
y[0] = 50; |
|||
y[ |
y[1] = y[2] = 150; |
||
x[2] = x[3] = 250; |
|||
y[ |
y[3] = 250; |
||
⚫ | |||
//initialize dragging flags to false |
|||
for (int i =0; i< 4; i++) { |
|||
permitDrag[i] = false; |
|||
⚫ | |||
} |
} |
||
Line 1,116: | Line 1,111: | ||
background(255); |
background(255); |
||
noFill(); |
noFill(); |
||
⚫ | |||
⚫ | |||
bezier (x[1], y[1], x[0], y[0], x[3], y[3], x[2], y[2]); |
bezier (x[1], y[1], x[0], y[0], x[3], y[3], x[2], y[2]); |
||
// |
// the bezier handles |
||
strokeWeight(1); |
strokeWeight(1); |
||
stroke(100); |
stroke(100); |
||
line(x[0], y[0], x[1], y[1]); |
line(x[0], y[0], x[1], y[1]); |
||
line(x[2], y[2], x[3], y[3]); |
line(x[2], y[2], x[3], y[3]); |
||
// |
// the anchor and control points |
||
stroke(0); |
stroke(0); |
||
fill(0); |
fill(0); |
||
Line 1,131: | Line 1,125: | ||
fill(255, 100, 10); |
fill(255, 100, 10); |
||
rectMode(CENTER); |
rectMode(CENTER); |
||
rect(x[i], y[i], |
rect(x[i], y[i], 5, 5); |
||
} else { |
} else { |
||
fill(0); |
fill(0); |
||
ellipse(x[i], y[i], |
ellipse(x[i], y[i], 5, 5); |
||
} |
} |
||
} |
} |
||
// |
// permit dragging |
||
for (int i =0; i< 4; i++) { |
for (int i =0; i< 4; i++) { |
||
if (permitDrag[i]) { |
if (permitDrag[i]) { |
||
Line 1,147: | Line 1,141: | ||
} |
} |
||
// release any point attached to the mouse |
|||
void mouseReleased () { |
void mouseReleased () { |
||
for (int i =0; i< 4; i++) { |
for (int i =0; i< 4; i++) { |
||
Line 1,154: | Line 1,147: | ||
} |
} |
||
// for dragg'n dem points |
|||
void mousePressed () { |
void mousePressed () { |
||
for (int i =0; i< 4; i++) { |
for (int i =0; i< 4; i++) { |
||
if (mouseX>=x[i]-5 && mouseX<=x[i]+ |
if (mouseX>=x[i]-5 && mouseX<=x[i]+10 && mouseY>=y[i]-5 && mouseY<=y[i]+10) { |
||
mouseY>=y[i]-5 && mouseY<=y[i]+ptSize+5) { |
|||
permitDrag[i] = true; |
permitDrag[i] = true; |
||
} |
} |
||
Line 1,164: | Line 1,155: | ||
} |
} |
||
// |
// hand curser when over dragging over points |
||
void mouseMoved () { |
void mouseMoved () { |
||
cursor(ARROW); |
cursor(ARROW); |
||
for (int i =0; i< 4; i++) { |
for (int i =0; i< 4; i++) { |
||
if (mouseX>=x[i]-5 && mouseX<=x[i]+ |
if (mouseX>=x[i]-5 && mouseX<=x[i]+10 && |
||
mouseY>=y[i]-5 && mouseY<=y[i]+ |
mouseY>=y[i]-5 && mouseY<=y[i]+10) { |
||
cursor(HAND); |
cursor(HAND); |
||
} |
} |