PImage[] imgs = new PImage[4]; // loaded images PImage img1,img2; // current images int curImg1 = 0, curImg2 = 1; // current images void setup() { size(400,600); for(int i = 0; i < imgs.length; i ++) imgs[i] = loadImage("img-"+(i+1)+".jpg"); img1 = imgs[curImg1]; img2 = imgs[curImg2]; } PImage blendSquares(PImage a, PImage b, int s) { PImage ret = new PImage(a.width,a.height); for(int y = 0; y < ret.height; y ++) { for(int x = 0; x < ret.width; x ++) { if((x+y)%s==0||(x-y)%s==0) pset(ret,x,y,pget(a,x,y)); else pset(ret,x,y,pget(b,x,y)); } } return ret; } PImage blendLookAt(PImage a, PImage b, int lx, int ly, int lr) { PImage ret = new PImage(a.width,a.height); for(int y = 0; y < ret.height; y ++) { for(int x = 0; x < ret.width; x ++) { float f = constrain(dist(x,y,lx,ly)/lr,0,1); f = f*f; // make it a bit more dramatic color ca = pget(a,x,y), cb = pget(b,x,y); float rr = red(ca)*f+(1-f)*red(cb); float rg = green(ca)*f+(1-f)*green(cb); float rb = blue(ca)*f+(1-f)*blue(cb); pset(ret,x,y,color(rr,rg,rb)); } } return ret; } void draw() { // compute the filtered images PImage f1 = blendSquares(img1,img2,constrain(int(map(mouseX,0,width/2,1,20)),1,20)); PImage f2 = blendLookAt(img1,img2,mouseX-width/2,mouseY-height/2,100); // draw them background(0); image(img1,0,0); image(img2,width/2,0); image(f1,0,height/2); image(f2,width/2,height/2); } void keyPressed() { if(key == ' ') { curImg1 = (curImg1+1)%imgs.length; curImg2 = (curImg2+1)%imgs.length; img1 = imgs[curImg1]; img2 = imgs[curImg2]; } else if(key == 'f') { // swap images int a = curImg1; curImg1 = curImg2; curImg2 = a; img1 = imgs[curImg1]; img2 = imgs[curImg2]; } } // START NO NOTES // code used to capture screenshots void pset(int x, int y, color c) { x = constrain(x,0,width-1); y = constrain(y,0,height-1); pixels[x+width*y] = c; } color pget(int x, int y) { x = constrain(x,0,width-1); y = constrain(y,0,height-1); return pixels[x+width*y]; } void pset(PImage i, int x, int y, color c) { x = constrain(x,0,i.width-1); y = constrain(y,0,i.height-1); i.pixels[x+i.width*y] = c; } color pget(PImage i, int x, int y) { x = constrain(x,0,i.width-1); y = constrain(y,0,i.height-1); return i.pixels[x+i.width*y]; } void keyReleased() { if(key == '`' && !online) save("sketch.png"); }