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

Content added Content deleted
Line 1,092: Line 1,092:
'''It can be run on line''' :<BR> [https://www.openprocessing.org/sketch/846556/ here.]
'''It can be run on line''' :<BR> [https://www.openprocessing.org/sketch/846556/ here.]
<lang>
<lang>
float[]x = new float[4];
float[] x = new float[4];
float[]y = new float[4];
float[] y = new float[4];
boolean[]permitDrag = new boolean[4];
boolean[] permitDrag = new boolean[4];


void setup() {
void setup() {
Line 1,112: Line 1,112:
noFill();
noFill();
stroke(0, 0, 255);
stroke(0, 0, 255);
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
// the bezier handles
strokeWeight(1);
strokeWeight(1);
Line 1,121: Line 1,121:
stroke(0);
stroke(0);
fill(0);
fill(0);
for (int i =0; i< 4; i++) {
for (int i = 0; i< 4; i++) {
if (i ==0 || i==3) {
if (i == 0 || i == 3) {
fill(255, 100, 10);
fill(255, 100, 10);
rectMode(CENTER);
rectMode(CENTER);
Line 1,133: Line 1,133:


// permit dragging
// permit dragging
for (int i =0; i< 4; i++) {
for (int i = 0; i < 4; i++) {
if (permitDrag[i]) {
if (permitDrag[i]) {
x[i] = mouseX;
x[i] = mouseX;
Line 1,142: Line 1,142:


void mouseReleased () {
void mouseReleased () {
for (int i =0; i< 4; i++) {
for (int i = 0; i < 4; i++) {
permitDrag[i] = false;
permitDrag[i] = false;
}
}
Line 1,148: Line 1,148:


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]+10 && mouseY>=y[i]-5 && mouseY<=y[i]+10) {
if (mouseX >= x[i]-5 && mouseX <= x[i]+10 && mouseY >= y[i]-5 && mouseY <= y[i]+10) {
permitDrag[i] = true;
permitDrag[i] = true;
}
}
Line 1,155: Line 1,155:
}
}


// hand curser when over dragging over points
// hand curser when 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]+10 && mouseY>=y[i]-5 && mouseY<=y[i]+10) {
if (mouseX >= x[i]-5 && mouseX <= x[i]+10 && mouseY >= y[i]-5 && mouseY <= y[i]+10) {
cursor(HAND);
cursor(HAND);
}
}
}
}
}
}</lang>
</lang>


=={{header|PureBasic}}==
=={{header|PureBasic}}==