Final Project #3
Posted: May 5th, 2010 | Author: Candice | Filed under: Phys Comp 10 | No Comments »During the weekend before the final class, I was on the 34th Street N/Q/R/W platform and saw someone playing with the public art installation. It inspired me to streamline what I was trying to do. It really could be as simple as entering the frame was the trigger and to step out would go back to the static silence.
I spent the last week of working on the project trying to figure out the array. I ended up going to Dan Shiffman for help on that and advice on how to improve my camera detection code. I was happy with the final product and think it could be fun to play with it in a different space further.
Haring Rocker Demo from Candice on Vimeo.
The final code:
//initialize camera reading - with Processing book example 16.2
import processing.video.*;
Capture video;
PImage backgroundImage;
float threshold = 50;//graphics soundtrack
import ddf.minim.*;
Minim minim;
AudioPlayer song1;
AudioPlayer song2;//imported graphics
PImage staticimg;
PImage[] images = new PImage[6];
//rows of haring image
int unit = 100;
int num;
Row [] rows;//SETUP
void setup(){
size (500,500);
//initialize cam
video = new Capture (this, width, height,30);
backgroundImage = createImage (video.width,video.height,RGB);// this loads song from the data folder
minim = new Minim(this);
//Calvin Harris, Neon Rocks - instrumental version
song1 = minim.loadFile("neonrocks.wav");
//from: http://www.freesound.org/samplesViewSingle.php?id=453
song2 = minim.loadFile("static.wav");//call images
staticimg = loadImage ("static-poster.jpg");
images[0] = loadImage ("blue_shape.png");
images[1] = loadImage ("green_shape.png");
images[2] = loadImage ("purple_shape.png");
images[3] = loadImage ("magenta_shape.png");
images[4] = loadImage ("red_shape.png");
images[5] = loadImage ("yellow_shape.png");// //haring rows
num = width/unit * width/unit;
rows = new Row [num];for (int i = 0; i < height/unit; i++) {
for (int j = 0; jint index = (i * height/unit) + j;
rows[index] = new Row(j*unit, i*unit, unit/2, unit/2);
}
}
}void draw(){
background(0);// Capture video
if (video.available()) {
video.read();
}
//loading sets of pixels
loadPixels();
video.loadPixels();
backgroundImage.loadPixels();int counter = 0;
// Begin loop to walk through every pixel
for (int x = 0; x < video.width; x ++ ) {
for (int y = 0; y < video.height; y ++ ) {
int loc = x + y*video.width; // Step 1, what is the 1D pixel location
color fgColor = video.pixels[loc]; // Step 2, what is the foreground color//recall the background color
color bgColor = backgroundImage.pixels[loc];// Step 4, compare the foreground and background color
float r1 = red(fgColor);
float g1 = green(fgColor);
float b1 = blue(fgColor);
float r2 = red(bgColor);
float g2 = green(bgColor);
float b2 = blue(bgColor);
float diff = dist(r1,g1,b1,r2,g2,b2);// how much is the difference
if (diff > threshold) {
// If so, display the foreground color
counter++;
} }
}
updatePixels();println(counter);
if (counter > 2500) {
for (int i = 0; i< num; i++){
rows[i].display();
rows[i].move();
song1.play();
song2.pause();
println("haring");
}} else {
image (staticimg, 0,0);
song2.play();
song1.pause();
song1.rewind();
println("static");
}
}void mousePressed() {
backgroundImage.copy(video,0,0,video.width,video.height,0,0,video.width,video.height);
backgroundImage.updatePixels();
}
class Row{
float mx, my;
int size = unit;
float x, y = 0;
float ydirection;
float yspeed;int whichImage;
Row (float imx, float imy, float ix, float iy) {
ydirection = 5;
yspeed = 5;
mx = imy;
my = imx;
x = int(ix);
y = int(iy);whichImage = int(random(6));
}void move(){
my = my + yspeed;
if (my > height) {
my = 0;
}
}void display(){
image (images[whichImage], mx, my);
}
}











