import processing.video.*; Capture cam; PImage back; // background image float tolerance = 0.1; // percent of the image different void setup() { size(640,480); smooth(); cam = new Capture(this,640,480); back = new PImage(cam.width,cam.height); back.loadPixels(); } void draw() { if (cam.available()) { cam.read(); cam.loadPixels(); // create an image of the foreground that is transparent where the background is visible float f = 0; for(int y = 0; y < cam.height; y ++) { for(int x = 0; x < cam.width; x ++) { color c1 = cam.pixels[x+y*cam.width]; color c2 = back.pixels[x+y*back.width]; f += dist(red(c1),green(c1),blue(c1),red(c2),green(c2),blue(c2)); } } f /= cam.width*cam.height*255; // update the background is movement was detected or keypressed if(f > tolerance || (keyPressed && key== ' ')) { back.copy(cam,0,0,cam.width,cam.height,0,0,cam.width,cam.height); back.loadPixels(); } // draw the image and the color if(f > tolerance) tint(255,128,128); else tint(255); image(cam,0,0); } } // START NO NOTES // code used to capture screenshots void keyReleased() { if(key == '`' && !online) save("sketch.png"); }