Bitmap/Bézier curves/Cubic: Difference between revisions

Line 1,092:
It can be run on line [https://www.openprocessing.org/sketch/846556/ here.]
<lang>
int ptSize = 6;
float[]x = new float[4];
float[]y = new float[4];
Line 1,100 ⟶ 1,099:
size(300, 300);
smooth();
// fill coordinatestartpoint arrayscoordinates
x[0] = x[1] = 50;
x[2] = x y[30] = width-50;
y[1] = y[02] = height/2-50150;
yx[2] = x[3] = height/2+50250;
y[13] = y[2] = height/2250;
}
 
//initialize dragging flags to false
for (int i =0; i< 4; i++) {
permitDrag[i] = false;
}
}
 
Line 1,116 ⟶ 1,111:
background(255);
noFill();
stroke(0, 300, 200255);
 
stroke(0, 30, 200);
bezier (x[1], y[1], x[0], y[0], x[3], y[3], x[2], y[2]);
// drawthe bezier handles
strokeWeight(1);
stroke(100);
line(x[0], y[0], x[1], y[1]);
line(x[2], y[2], x[3], y[3]);
// drawthe anchor/ and control points
stroke(0);
fill(0);
Line 1,131 ⟶ 1,125:
fill(255, 100, 10);
rectMode(CENTER);
rect(x[i], y[i], ptSize5, ptSize5);
} else {
fill(0);
ellipse(x[i], y[i], ptSize5, ptSize5);
}
}
 
// startpermit dragging if flag true
for (int i =0; i< 4; i++) {
if (permitDrag[i]) {
Line 1,147 ⟶ 1,141:
}
 
// release any point attached to the mouse
void mouseReleased () {
for (int i =0; i< 4; i++) {
Line 1,154 ⟶ 1,147:
}
 
// for dragg'n dem points
void mousePressed () {
for (int i =0; i< 4; i++) {
if (mouseX>=x[i]-5 && mouseX<=x[i]+ptSize+10 && mouseY>=y[i]-5 && mouseY<=y[i]+10) {
mouseY>=y[i]-5 && mouseY<=y[i]+ptSize+5) {
permitDrag[i] = true;
}
Line 1,164 ⟶ 1,155:
}
 
// show hand curser when over draggabledragging over points
void mouseMoved () {
cursor(ARROW);
for (int i =0; i< 4; i++) {
if (mouseX>=x[i]-5 && mouseX<=x[i]+ptSize+510 &&
mouseY>=y[i]-5 && mouseY<=y[i]+ptSize+510) {
cursor(HAND);
}
47

edits