//adapted by joana kelly from the brightness tracking code written by Golan Levin int numFrames = 13; PImage[] images = new PImage[numFrames]; // Tracks the brightest pixel in a live video signal import processing.video.*; Capture video; void setup(){ background(0); size(640, 480); for (int i = 0; i < images.length; i++){ String imageName = "sprite" + nf(i,0) + ".png"; // println(imageName); images[i] = loadImage(imageName); } video = new Capture(this, width, height, 30); noStroke(); smooth(); } void draw() { frameRate(10); int frame = frameCount % numFrames; if (video.available()) { video.read(); image(video, 0, 0, 100, 80); // Draw the webcam video onto the screen int brightestX = 0; // X-coordinate of the brightest video pixel int brightestY = 0; // Y-coordinate of the brightest video pixel int PbrightestX = brightestX -1; int PbrightestY = brightestY-1; float brightestValue = 0; // Brightness of the brightest video pixel // Search for the brightest pixel: For each row of pixels in the video image and // for each pixel in the yth row, compute each pixel's index in the video video.loadPixels(); int index = 0; for (int y = 0; y < video.height; y++) { for (int x = 0; x < video.width; x++) { // Get the color stored in the pixel int loc = (video.width - x - 1) + y*video.width; int pixelValue = video.pixels[loc]; // Determine the brightness of the pixel float pixelBrightness = brightness(pixelValue); // If that value is brighter than any previous, then store the // brightness of that pixel, as well as its (x,y) location // callibrate brightness if (pixelBrightness > 100){ brightestValue = pixelBrightness; // println("brightness is " + brightestValue); // println("pixel brightness is" + pixelBrightness); brightestY = y; brightestX = x; } index++; } } // Draw a large, yellow circle at the brightest pixel //rect(0,0,width, height); //for (float z = 0; z<255; z++){ // fill(random(255+z),random(255),random(255)); // } image(images[frame], brightestX, brightestY); // rect(brightestX, brightestY,12,12); // filter(THRESHOLD, 0.3); } }