video in processing

 

For this project I did exercise  16-2 from the book “Learning Processing”of Daniel Schiffman,,, and instead of drawing the image shown with ellipse i change it for squares.

here’s the video.

 

and here’s the code:

import processing.video.*;

Capture video;

void setup(){
size (320,240);

video = new Capture(this,320,240,15);
video.start();
background(0);
}

void draw(){
if (video.available()){
video.read();
}
loadPixels();
video.loadPixels();
// for (int x = 0; x<video.width; x++){
// for (int y = 0; y < video.height; y ++){
int x = int(random(video.width));
int y= int(random(video.height));
int loc = x + y*video.width;

float r,g,b;

r = red(video.pixels[loc]);
g = green(video.pixels[loc]);
b = blue(video.pixels[loc]);
noStroke();

fill(r,g,b,100);
rect(x,y,13,13);

}

Leave a Reply