code

import processing.video.*;

int time;
int wait = 1000; //delay in milliseconds
int y = 0;
int x = 0;
int img_x_size = 10; //width of drawn cube
int img_y_size = 10; //height of drawn cube
int offset_y = int(img_y_size/2); //optional offset
PImage destination;
Capture cam;

void setup() {
size(displayWidth, displayHeight,P3D);
img_x_size = int(displayWidth/2);
img_y_size = int(displayHeight/3);
frameRate(30);
background(0);
noStroke();
time = millis();
destination = createImage(img_x_size, img_y_size, RGB);
String[] cameras = Capture.list();

if (cameras.length == 0) {
println(“There are no cameras available for capture.”);
exit();
} else {
println(“Available cameras:”);
for (int i = 0; i < cameras.length; i++) {
println(cameras[i]);
}

// The camera can be initialized directly using an
// element from the array returned by list():
cam = new Capture(this, cameras[0]);
cam.start();
}
}

boolean sketchFullScreen() {
return true;
}

void draw() {
if (cam.available() == true) {
cam.read();
if(millis() – time >= wait){
time = millis();//also update the stored time
//image(cam,x,y,img_x_size,img_y_size);
int img_color_x = int(random(cam.width));
int img_color_y = int(random(cam.height));
color img_color = cam.get(img_color_x,img_color_y);
fill(img_color);
rect(x,y,img_x_size,img_y_size);
//image(destination,x,y,img_x_size,img_y_size);
y += img_y_size;
if(x >= displayWidth){
y = 0;
x = 0;
}
if(y >= displayHeight){
if(x == img_x_size){
x = 0;
}else{
x = img_x_size;
}
//y = 0 + offset_y;
y = 0;
saveFrame(“data/frame-######.png”);
//offset_y = offset_y + (img_x_size /2);
//if(offset_y>=480){
//y = 0;
//offset_y = img_y_size/2;
//}
}
}
}
}

Leave a Reply