By using a webcam Processing can see our world :) You can show live video in Processing, or capture single images as a photo camera would do.
Very few lines of code are needed to show a camera live feed. Just try it! :)
Type in the code - then walk yourself through each line to make sure you understand what is happening. Then try the challenges given to you in the //comments .
import processing.video.*;
Capture cam;
void setup() {
size(600, 300);
cam = new Capture(this, 320, 240, 30);
cam.start();
}
void draw() {
if(cam.available()) {
cam.read();
}
image(cam, random(width), random(height));
//try replacing random width and random height with a fixed place like 0,0
//try taking out mousePressed and changing it to a keyPressed
if(mousePressed){
noLoop();
}
}
void draw() {
// nothing here
}
void keyPressed() {
if (cam.available()) {
cam.read();
image(cam, 0, 0);
}
}