//adapted by joana kelly from the brightness tracking code written by Golan Levin int frame = 0; 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(1000, 700); for (int i = 0; i < images.length; i++){ String imageName = "sprite" + nf(i,0) + ".png"; images[i] = loadImage(imageName); } video = new Capture(this, width, height, 30); noStroke(); smooth(); } void draw() { frame++; 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; brightestY = y; brightestX = x; } index++; } } for (float y = 0; y <= 100; y+=.01){ fill(0, y); } //println(frame); rect(0,0, width, height); image(images[frame], brightestX, brightestY); for (int x = 0; x == frame % 13; x++){ saveFrame("####.jpg"); } } }