--- Processing3.0 Code---
The ball fallow the light
import processing.video.*;
int x, y;
Capture cam;
void setup () {
size (640, 360);
frameRate(30);
background(0);
cam = new Capture (this, 640, 360, "FaceTime HD Camera (Built-in)", 30);
cam.start();
//printArray(Capture.list());
}
void draw() {
if (cam.available()) {
cam.read();
cam.loadPixels();
float theLight = 0;
int brightnessPix =0;
for (int i=0; i<cam.pixels.length; i++) {
if (brightness(cam.pixels[i]) > theLight) {
theLight= brightness (cam.pixels[i]);
brightnessPix = i;
}
}
x = brightnessPix % cam.width;
y = brightnessPix / cam.width;
}
println (x,y);
image (cam, 0, 0);
fill(0, 255, 0);
ellipse (x, y, 20, 20);
}