This browser does not have a Java Plug-in.
Get the latest Java Plug-in here.

import processing.video.*; PImage blinky; PImage pinky; PImage inkey; PImage clyde; Capture video; float x = 0.0; float y = 0.0; float a = 0.0; float b = 0.0; float c = 0.0; float d = 0.0; float e = 0.0; float f = 0.0; float easing = 0.041; // numbers 0.0 to 10 void setup() { size(640, 480); // Change size to 320 x 240 if too slow at 640 x 480 // Uses the default video input, see the reference if this causes an error video = new Capture(this, width, height, 30); noStroke(); smooth(); blinky = loadImage("blinky.gif"); pinky = loadImage("pinky.gif"); inkey = loadImage("inkey.gif"); clyde = loadImage("clyde.gif"); } void draw() { if (video.available()) { video.read(); image(video, 0, 0, width, height); // 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 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 pixelValue = video.pixels[index]; // 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 if (pixelBrightness > brightestValue) { brightestValue = pixelBrightness; // whats the difference between brightestValue and pixelBrightness? brightestY = y; brightestX = x; } index++; } } // Draw a large, yellow circle at the brightest pixel float targetX = brightestX; x += (targetX - x) * easing; float targetY = brightestY; y += (targetY - y) * easing; float targetA = x; a += (targetA - a) * easing; float targetB = y; b += (targetB - b) * easing; float targetC = a; c += (targetC - c) * easing; float targetD = b; d += (targetD - d) * easing; float targetE = c; e += (targetE - e) * easing; float targetF = d; f += (targetF - f) * easing; fill(255, 204, 0, 128); ellipse(brightestX, brightestY, 100, 100); // this ellipse needs a pacman mouth image(blinky, x, y); image(pinky, a, b); image(inkey, c, d); image(clyde, e, f); } }

Source code: pacmangame

Built with Processing