Processing Project – Final Code, Final Product

Here is the final code and the final piece I created:


import processing.video.*;

int cellSize = 15;
int cols, rows;

Capture video;

void setup() {
size(640, 480);
frameRate(30);
cols = width / cellSize;
rows = height / cellSize;
colorMode(RGB, 255, 255, 255, 100);

video = new Capture(this, width, height);

video.start();

background(0);
}
void draw() {
if (video.available()) {
video.read();
video.loadPixels();

for (int i = 0; i < cols; i++) {

for (int j = 0; j < rows; j++) {

int x = i*cellSize;
int y = j*cellSize;
int loc = (video.width - x - 1) + y*video.width; // Reversing x to mirror the image

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

color c = color(r, g, b, 75);

pushMatrix();
translate(x+cellSize/2, y+cellSize/2);

rectMode(CENTER);
fill(c);
noStroke();
rect(0, 0, cellSize+1, cellSize+1);
popMatrix();
}
}
}
}

Screen Shot 2015-01-26 at 06.35.07

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s