// Inversion Filter 1.0 // by Mario Klingemann // http://incubator.quasimondo.com // contact: mario@quasimondo.com // // Reuse of this code is permitted // as long as this copyright notice // is included. BImage a; int xc,yc; int k; boolean drag; boolean newFrame; void setup() { drag=false; k=80*80; // Uncomment this Block if you want to use live video: /* size(320,240); newFrame = false; a=new BImage(320,240); beginVideo(320, 240,18); */ a=loadImage("sweden.jpg"); size(a.width, a.height); noStroke(); } void mousePressed(){ drag=true; xc=mouseX; yc=mouseY; } void mouseReleased(){ drag=false; } void mouseDragged(){ int dx= xc-mouseX; int dy= yc-mouseY; k=5*(dx*dx+dy*dy); } void loop() { // Uncomment this Block if you want to use live video: /* if(newFrame) { System.arraycopy(video.pixels, 0, a.pixels, 0, video.pixels.length); newFrame = false; } */ if (!drag){ xc=mouseX; yc=mouseY; } inversion(a); } void inversion(BImage img){ int x,y,i,d,xn,yn,dx,dy; boolean mx,my; int[] pix=img.pixels; i=0; for (y=0;y=width){ xn-=width; mx=!mx; } my=false; while (yn<0){ yn+=height; my=!my; } while (yn>=height){ yn-= height; my=!my; } if (mx){ xn=width-1-xn; } if (my){ yn=height-1-yn; } pixels[i++]=pix[xn+yn*width]; } } } // Uncomment this function for live Video: /* void videoEvent(){ newFrame = true; } */