ArrayList allPoints = new ArrayList(); ArrayList allBez = new ArrayList(); void setup() { size(500, 500); // allBez.add(new Bez(85, 20, 10, 10, 90, 90, 15, 80)); // allBez.add(new Bez(30, 20, 80, 5, 80, 75, 30, 75)); // allBez.add(new Bez(75,30,75,80,5,80,20,30)); for(int i = 0; i < 3; i++){ allBez.add(new Bez()); } } void draw() { background(255); for(Bez b : allBez){ b.draw(); } } Point dragPoint = null; void mousePressed(){ dragPoint = nearPoint(); } void mouseDragged(){ if(dragPoint != null){ dragPoint.x = mouseX; dragPoint.y = mouseY; } } void mouseReleased(){ dragPoint = null; } Point nearPoint(){ for(Point p : allPoints){ if(p.mouseNear()) return p; } return null; } void lineByPoint(Point a, Point b) { line(a.x, a.y, b.x, b.y); } void bezierByPoint(Point a1, Point c1, Point c2, Point a2) { bezier(a1.x, a1.y, c1.x, c1.y, c2.x, c2.y, a2.x, a2.y); } void circle(Point a) { ellipse(a.x, a.y, 10, 10); } class Bez { Point a1, c1, a2, c2; Bez(){ this(random(500),random(500),random(500),random(500), random(500),random(500),random(500),random(500)); } Bez(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) { a1 = new Point(x1, y1); allPoints.add(a1); c1 = new Point(x2, y2); allPoints.add(c1); c2 = new Point(x3, y3); allPoints.add(c2); a2 = new Point(x4, y4); allPoints.add(a2); } void draw(){ fill(255); strokeWeight(2); stroke(255,0,0); lineByPoint(a1,c1); lineByPoint(a2,c2); a1.draw(); a2.draw(); c1.draw(); c2.draw(); noFill(); stroke(0); bezierByPoint(a1, c1, c2, a2); } } class Point { float x, y; Point(float px, float py) { x = px; y = py; } void draw(){ if(mouseNear()) ellipse(x,y,20,20); else ellipse(x,y,10,10); } boolean mouseNear() { if (dist(x, y, mouseX, mouseY) < 15) { return true; } return false; } }