int x1=85; int y1=20; int cx1=10; int cy1=10; int cx2=90; int cy2=90; int x2=15; int y2=80; boolean x1_up=false, x1_down=false, cx1_up=false, cx1_down=false, cx2_up=false, cx2_down=false, x2_up=false, x2_down=false; void draw() { background(255,255,255); stroke(255, 102, 0); line(x1,y1, cx1, cy1); line(cx2, cy2, x2, y2); ellipse(x1,y1,5,5); ellipse(cx1,cy1,5,5); ellipse(x2,y2,5,5); ellipse(cx2,cy2,5,5); stroke(0, 0, 0); bezier(x1,y1, cx1, cy1, cx2, cy2, x2, y2); noLoop(); } void mouseReleased() { if (x1_up) { println("ignore x1"); x1_up = false; x1_down = true; } if (x2_up) { println("ignore x2"); x2_up = false; x2_down = true; } if (cx1_up) { println("ignore cx1"); cx1_up = false; cx1_down = true; } if (cx2_up) { println("ignore cx2"); cx2_up = false; cx2_down = true; } } void mouseDragged() { if (x1_up && mouseX < width && mouseX > 0 && mouseY > 0 && mouseY < height) { println("drag x1"); x1 = mouseX; y1 = mouseY; } if (x2_up && mouseX < width && mouseX > 0 && mouseY > 0 && mouseY < height) { println("drag x2"); x2 = mouseX; y2 = mouseY; } if (cx1_up && mouseX < width && mouseX > 0 && mouseY > 0 && mouseY < height) { println("drag cx1"); cx1 = mouseX; cy1 = mouseY; } if (cx2_up && mouseX < width && mouseX > 0 && mouseY > 0 && mouseY < height) { println("drag cx2"); cx2 = mouseX; cy2 = mouseY; } redraw(); } void mousePressed() { // To prevent point from ending up on top of one another and then being dragged together without being able // to split them up again, we use 'else'. This means that x1 will always be on top, x2 next, then cx1 and // then cx2. if ((!x1_up) && ((mouseX <= (x1 + 5) && mouseX >= (x1 - 5)) && (mouseY <= (y1 + 5) && mouseY >= (y1 - 5)))) { println("lift x1"); x1_up = true; } else if ((!x2_up) && ((mouseX <= (x2 + 5) && mouseX >= (x2 - 5)) && (mouseY <= (y2 + 5) && mouseY >= (y2 - 5)))) { println("lift x2"); x2_up = true; } else if ((!cx1_up) && ((mouseX <= (cx1 + 5) && mouseX >= (cx1 - 5)) && (mouseY <= (cy1 + 5) && mouseY >= (cy1 - 5)))) { println("lift cx1"); cx1_up = true; } else if ((!cx2_up) && ((mouseX <= (cx2 + 5) && mouseX >= (cx2 - 5)) && (mouseY <= (cy2 + 5) && mouseY >= (cy2 - 5)))) { println("lift cx2"); cx2_up = true; } }