März 5, 2012
import processing.video.*; int W = 640; int H = 480; color pColor; Capture cam; int res = 4; int thresh = 20; color[] buffer; void setup() { size ( W, H ); background(0); buffer = new color[W * H]; cam = new Capture(this, W, H); } void captureEvent(Capture cam) { cam.read(); } void draw() { sampleAndPaint(); swapBuffer(); } void sampleAndPaint() { fill(0, 30); rect(0, 0, W, H); for ( int i = 0; i < W; i+= res ) { for ( int j = 0; j < H; j+=res ) { int offset = i + j * W; color c = cam.pixels[offset]; color r = buffer[offset]; float cB = brightness(c); float rB = brightness(r); float delta = abs ( cB - rB ); if ( delta > thresh ) { fill ( 0, 255, 0 ); noStroke(); //res = int(random(1,res)); rect ( i, j, res, res ); } } } } void swapBuffer() { arrayCopy(cam.pixels, buffer); }