class Point2f { float ox,oy; float x,y; Point2f(float x, float y) { this.ox=x; this.oy=y; this.x=x; this.y=y; } } class Line { Vector points = new Vector(); void add(Point2f p) { points.add(p); } Point2f get(int i) { return (Point2f)points.elementAt(i); } int size() { return points.size(); } } Vector lines = new Vector(); int gw = 96; void setup() { size(400,400); //smooth(); // verticals for (int i = 0; i <= gw; i++) { Line line = new Line(); for (int j = 0; j <= gw; j++) { line.add(new Point2f(i*width/gw,j*height/gw)); } lines.add(line); } // horizontals for (int i = 0; i <= gw; i++) { Line line = new Line(); for (int j = 0; j <= gw; j++) { line.add(new Point2f(j*width/gw,i*height/gw)); } lines.add(line); } } float sc = 2.0; void draw() { background(255); //colorMode(HSB); noFill(); strokeWeight(1); for (int i = 0; i < lines.size(); i++) { Line line = (Line)lines.elementAt(i); beginShape(LINE_STRIP); for (int j = 0; j < line.size(); j++) { Point2f point = line.get(j); if (mousePressed) { float d2 = sq(point.x - mouseX) + sq(point.y - mouseY); if (d2 > 0.15) { float d = sqrt(d2); point.x += ((point.x - mouseX)/d*sc); point.y += ((point.y - mouseY)/d*sc); } } else { float d2 = sq(point.x - point.ox) + sq(point.y - point.oy); if (d2 > 0.1) { float d = sqrt(d2); point.x += (point.ox - point.x)/max(sc,1.0); point.y += (point.oy - point.y)/max(sc,1.0); } } stroke(min(255.0*abs(point.x-point.ox)/100.0,255.0),min(255.0*abs(point.y-point.oy)/100.0,255.0),1.0); curveVertex(point.x,point.y); if (j == 0 || j == line.size()-1) { curveVertex(point.x,point.y); } } endShape(); } if (mousePressed) { if (sc < 10.0) { sc = sc*1.1; } } else { if (sc > 0.1) { sc /= 1.01; } } }