import processing.video.*; Capture cam; PGraphics img; color selected = color(0,255,0); // selected color void setup() { size(640,480); smooth(); cam = new Capture(this,640,480); cam.start(); img = createGraphics(640,480,JAVA2D); } void draw() { if (cam.available()) { cam.read(); cam.loadPixels(); // pick a different selected color, if you want if(mousePressed) selected = cam.pixels[mouseX+mouseY*cam.width]; // search for the pixel closer to the selected color int sx = 0, sy = 0; // selected position float minDist = 1000; // put a huge number so we do not have to care for(int y = 0; y < cam.height; y ++) { for(int x = 0; x < cam.width; x ++) { color c = cam.pixels[x+y*cam.width]; float d = dist(red(c),green(c),blue(c), red(selected),green(selected),blue(selected)); if(d < minDist) { minDist = d; sx = x; sy = y; } } } // update the painted image img.beginDraw(); img.smooth(); img.fill(selected,100); img.noStroke(); img.ellipse(sx,sy,25,25); img.endDraw(); // draw the cam image and on top of that draw the painted image image(cam,0,0); image(img,0,0); noFill(); stroke(200,255,200); strokeWeight(5); ellipse(sx,sy,50,50); } } void keyPressed() { // clear if(key == ' ') img = createGraphics(cam.width,cam.height,JAVA2D); } // START NO NOTES // code used to capture screenshots void keyReleased() { if(key == '`' && !online) save("sketch.png"); }