// lens demo // author: info@toxi.co.uk // curvature of the lens: 1 = normal spherical, >1 = increasingly extreme distortion // 0 = flat zoom, < -1 = inverse lens (as seen from inside the lens) float curvature=1; int gridSize=10; BImage tex; float radius=0,maxRadius=100; void setup() { size(200,200); noStroke(); tex=loadImage("milan_rubbish.jpg"); } void loop() { background(200); // click mouse to increase effect at position if (mousePressed) { radius+=(maxRadius-radius)*0.1; } else { radius*=0.98; } if (curvature<0) translate(0,0,-100); for(int y=0; y<=height; y+=gridSize) { float sqy=sq(mouseY-y), sqy1=sq(mouseY-(y+gridSize)); beginShape(TRIANGLE_STRIP); texture(tex); for(int x=0; x<=width; x+=gridSize) { vertex(x,y,min(max(radius-sqrt(sq(mouseX-x)+sqy)*curvature,0),200),x,y); vertex(x,y+gridSize,min(max(radius-sqrt(sq(mouseX-x)+sqy1)*curvature,0),200),x,y+gridSize); } endShape(); } }