PImage painting; PImage blurred; // to speed things up PImage maskImage; int lastX, lastY; void setup() { println("George Pollard – Assignment 2 – Image Processing"); painting = loadImage("/home/porges/Desktop/processing work/escher/data/mask.png"); maskImage = loadImage("/home/porges/Desktop/processing work/escher/data/escher.jpg"); size(painting.width, painting.height); //cache a blurred version image(painting, 0, 0); filter(BLUR,8); blurred = get(); //only update when told to by the mouse frameRate(0); } void draw() { int x1 = mouseX - maskImage.width/2; int y1 = mouseY - maskImage.height/2; x1 = clamp(x1, 0, width - maskImage.width); y1 = clamp(y1, 0, height - maskImage.height); //Only blit the needed part; save the planet! mix(blurred, lastX, lastY, lastX, lastY, maskImage.width, maskImage.height,false); //image(blurred,0,0); PImage glass = painting.get(x1,y1,maskImage.width, maskImage.height); /* Mask it; */ for (int x = 0; x < maskImage.width; x++) for (int y = 0; y < maskImage.height; y++) { glass.set(x,y, color( red(glass.get(x,y)), green(glass.get(x,y)), blue(glass.get(x,y)), red(maskImage.get(x,y)) )); } mix(glass, 0, 0, x1, y1, maskImage.width, maskImage.height, true); lastX = x1; lastY = y1; } void mouseMoved() { redraw(); } void mix(PImage img, int x1, int y1, int x2, int y2, int w, int h, boolean alphaPresent) { if (alphaPresent) blend(img, x1, y1, w, h, x2, y2, w, h, BLEND); else copy(img, x1, y1, w, h, x2, y2, w, h); } int clamp(int val, int low, int high) { return val <= low ? low : val >= high ? high : val; }