« CTIN 405 - Sketch 1 | Main | CTIN 405 - First iPhone app »

CTIN 544 Library Assignment

sketch.jpg

Here is the code for my second sketch:

import JMyron.*;

JMyron theMov;
int[] currFrame;
int[] prevFrame;
int[] fadeFrame;
int tolerance;
int modNum;
boolean revealing;

void setup() {
size(640, 480);

theMov = new JMyron();
theMov.start(width, height);
theMov.findGlobs(0);

// initialize the pixel arrays to avoid a NullPointerException
loadPixels();
currFrame = prevFrame = fadeFrame = pixels;

tolerance = 53;
modNum = 1;
revealing = true;
}

void draw() {
// erase the previous image

theMov.update();
// save the last frame before updating it
prevFrame = currFrame;
currFrame = theMov.image();

// draw each pixel to the screen only if its change factor is
// higher than the tolerance value
loadPixels();
for (int i=0; i < width*height; i++) {
if(brightness(pixels[i])<255)
{
fadeFrame[i] = int(brightness(pixels[i]+modNum));
if(brightness(pixels[i])>255)
{
fadeFrame[i] = color(255,255,255);
}
}
}
background(255);

for (int i=0; i < width*height; i++) {
pixels[i] = color(fadeFrame[i]);
if (comparePixels(i)) {
pixels[i] = color(0);
fadeFrame[i] = color(0);
}

}
updatePixels();
}

boolean comparePixels(int index) {
if (Math.abs(red(currFrame[index])-red(prevFrame[index])) < tolerance)
if (Math.abs(green(currFrame[index])-green(prevFrame[index])) < tolerance)
if (Math.abs(blue(currFrame[index])-blue(prevFrame[index])) < tolerance)
return !revealing;

return revealing;
}

void keyReleased() {
if (key == '.' || key == '>') {
// increase tolerance
tolerance += 2;
} else if (key == ',' || key == '<') {
// decrease tolerance
tolerance -= 2;
}
else if (key == '+' || key == '=') {
// decrease tolerance
modNum += 1;
println(modNum);
}
else if (key == '-' || key == '_') {
// decrease tolerance
if(modNum>0)
{
modNum -= 1;
}
println(modNum);
}
}

public void stop() {
theMov.stop();
super.stop();
}

Post a comment

About

This page contains a single entry from the blog posted on January 29, 2009 5:10 PM.

The previous post in this blog was CTIN 405 - Sketch 1.

The next post in this blog is CTIN 405 - First iPhone app.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.31