import processing.video.*; Ball[] ourBalls; int numBalls = 1; Capture video; float targetRed = 255.0; //set some numbers for the target you are chasing float targetGreen = 0.0; float targetBlue = 0.0; void setup() { video = new Capture(this,320, 240, 12); //initiate the video, resolution and frame rate size(320, 240); //give you Processing window a size ourBalls = new Ball[numBalls]; for (int j = 0;j < ourBalls.length; j=j+1) { //Ball(int windowWidth, int windowHeight, int ballSize, int xPosition, // int yPosition, int xDir, int yDir color anchobicolor = color (random(0), random(0),random(255)); ourBalls[j] = new Ball(anchobicolor, width, height, 20 ,30,j , 4, 4); } } void captureEvent(Capture camera) { camera.read(); ///////////////////// } void draw() { background(255); float worldRecord = 1000.0; //intialize the worldrecord int xFound = 0; // initialize the location of the red tracking ball int yFound = 0; for(int j=0; j < video.height; j=j+1) { //for each row for(int i=0; i < video.width; i=i+1) { //for each column //get the color of this pixels //find pixel in linear array using formula: pos = row*rowWidth+column color pix = video.pixels[j*video.width+i]; //find the difference float diff = abs(targetRed - red(pix)) + abs(targetGreen - green(pix)) + abs(targetBlue - blue(pix)); if (diff< worldRecord){ // if this is closest to our target color worldRecord = diff; yFound = j; //mark the spot for drawing it later xFound = i; } } } image(video,0,0); //draw the video, this might be optional //after all the pixels have been tested, draw the winner // fill(255,0,0); //ellipse(xFound, yFound, 10, 10); for (int j = 0; j < ourBalls.length; j=j+1) { ourBalls[j].display(xFound,yFound); } } //void mousePressed(){ //allow the target color to be changed // color pix = video.pixels[mouseY*video.width+mouseX]; // targetRed = red(pix); //get the color of the pixel they clicked on /// targetGreen = green(pix); // targetBlue = blue(pix); //}