class Anchors { Anchors() { points = new PParticle[NUM_ANCHOR_POINTS]; for (int i = 0; i < points.length; i++) { points[i] = new PParticle(random(0, width - 10), random(0, height - 10), physics); points[i].particle.makeFixed(); } selectedPoint = null; } void render() { noStroke(); fill(10, 10, 200); for (int i = 0; i < points.length; i++) ellipse(points[i].x, points[i].y, 10, 10); noFill(); } boolean selectPoint(float x, float y, float r) { selectedPoint = null; PVector p = new PVector(x, y); for (int i = 0; i < points.length; i++) if (points[i].dist(p) < r) { selectedPoint = points[i]; return true; } return false; } void setSelectedPoint(float x, float y) { if (selectedPoint != null) { selectedPoint.moveTo(x, y); } } int getAnchorIndex(PVector p, float r) { for (int i = 0; i < points.length; i++) if (points[i].dist(p) < r) return i; return -1; } void clear() { for (int i = 0; i < points.length; i++) points[i].restart(physics); } void displaceX() { for (int i = 0; i < points.length; i++) { float x = points[i].x + 0.5; if (width < x) x = 0; else if (x < 0) x = width; points[i].moveTo(x, points[i].y); } } void displaceY() { for (int i = 0; i < points.length; i++) { float y = points[i].y + 0.5; if (width < y) y = 0; else if (y < 0) y = height; points[i].moveTo(points[i].x, y); } } void rotateAroundScreenCenter() { float c = cos(0.001); float s = sin(0.001); for (int i = 0; i < points.length; i++) { float x = points[i].x - 0.5 * width; float y = points[i].y - 0.5 * height; float newx = c * x + s * y; float newy = -s * x + c * y; points[i].moveTo(newx + 0.5 * width, newy + 0.5 * height); } } PParticle[] points; PParticle selectedPoint; }