import processing.video.*; PImage mirror; Capture video; int numPixels; boolean useCam = true; float sigmoidScale = 3.0; float desatFactor = 0.125; color erase = color(100,255,0); color tempC; int pixNum, pixNumFlip; void setup() { mirror = loadImage("mirror2.png"); mirror.loadPixels(); size(mirror.width, mirror.height); frameRate(15); numPixels = width*height; loadPixels(); ellipseMode(RADIUS); video = new Capture(this, width, height); video.start(); } void draw() { if(video.available()){ background(255); drawShadow(); drawGrnScreen(); loadPixels(); video.read(); video.loadPixels(); for( int i = 0; i < height; i++) { for( int j = 0; j < width; j++ ) { pixNum = i*width+j; if( pixels[pixNum] == erase ) { pixNumFlip = i*width+(width-j); tempC = mirror.pixels[pixNum]; float k = intensity(tempC)/255.0; k = sigmoid((k-0.5)*sigmoidScale); // This method may be a little faster, but is harder to understand... //tempC = lerpColor(tempC, desaturate(video.pixels[pixNumFlip],desatFactor), k); //pixels[pixNum] = 0xff000000 | (round(red(tempC)) << 16) | (round(green(tempC)) << 8) | round(blue(tempC)); // ... so I'm just using this for now. pixels[pixNum] = lerpColor(tempC, desaturate(video.pixels[pixNumFlip],desatFactor), k); } } } updatePixels(); drawFrame(); ///fill(0); ///text(nf(frameRate,2,1),10,20); } } boolean looping = true; void keyPressed() { if (key == ' ') { if( looping ) { noLoop(); } else { loop(); } looping = !looping; } } float cx = 1; float cy = -1; float rx = 286.0; float ry = 365.0; void drawShadow() { pushStyle(); float offsetX = -8; float offsetY = 10; strokeWeight(2); noFill(); for( int i = 1; i < 32; i++ ) { stroke(32, (32-i)*4); ellipse(width/2+cx+offsetX, height/2+cy+offsetY, rx-32+2*i, ry-32+2*i); } popStyle(); } void drawGrnScreen() { pushStyle(); fill(erase); noStroke(); ellipse(width/2+cx, height/2+cy, rx, ry); popStyle(); } void drawFrame() { pushStyle(); noFill(); stroke(8); strokeWeight(4); ellipse(width/2+cx, height/2+cy, rx, ry); popStyle(); } float intensity(color c) { return 0.30*red(c)+0.59*green(c)+0.11*blue(c); } color desaturate(color c, float f) { float i = intensity(c); return lerpColor(c, color(i,i,i), f); } float sigmoid(float f ) { return 1.0/(1+exp(-1*f)); }