Februar 24, 2012
import processing.video.*; Capture video; PShape [] s; int index = 0; color trackColor; void setup() { size(640,480); video = new Capture(this,width,height,15); trackColor = color(200,200,0); s = new PShape[3]; s[0] = loadShape("biene.svg"); s[1] = loadShape("auge.svg"); s[2] = loadShape("kaefer.svg"); shapeMode(CENTER); smooth(); } void draw() { if (video.available()) { video.read(); } video.loadPixels(); image(video,0,0); float worldRecord = 500; int closestX = 0; int closestY = 0; for (int x = 0; x < video.width; x ++ ) { for (int y = 0; y < video.height; y ++ ) { int loc = x + y*video.width; color currentColor = video.pixels[loc]; float r1 = red(currentColor); float g1 = green(currentColor); float b1 = blue(currentColor); float r2 = red(trackColor); float g2 = green(trackColor); float b2 = blue(trackColor); float d = dist(r1,g1,b1,r2,g2,b2); if (d < worldRecord) { worldRecord = d; closestX = x; closestY = y; } } } if (worldRecord < 10) { smooth(); shape(s[index], closestX, closestY, 70, 70); } } void mousePressed() { int loc = mouseX + mouseY*video.width; trackColor = video.pixels[loc]; } void keyPressed() { if(keyPressed == true) { index++; } if(index == s.length) { index = 0; } }