« December 2008 | Main | February 2009 »

January 2009 Archives

January 22, 2009

CTIN 544 - First Processing sketch

processing1.png

As I incorporated the video camera, I can't post the exported sketch, but here is the code for my first assignment:

import processing.video.*;

Capture cam;

int xPos = 140;
int yPos = 480;
float percent = 0;

void setup()
{
size(760,480);
background(0);
smooth();
cam = new Capture(this, 320,240);
}

void draw()
{
//background(0);
fill(random(254));
noStroke();
ellipse(xPos,yPos,90,90);

float time = millis();
percent = (time % 10000)/10000;

xPos = int(800*percent);
float pos = abs(380-xPos);
int yLength = int(sqrt(sq(400) + sq(pos)));
yPos = yLength - 100;
fill(255);
ellipse(xPos,yPos,90,90);

stroke(random(200));
int sticks = int(50 * abs(0.5 - percent));
println("STICKS" + sticks);
for(int i=0;i<=sticks;i++)
{
stroke(random(200));
int lineX = int(random(760));
line(lineX, 480, lineX, 0);
}
for(int i=0;i<=18;i++)
{
stroke(0);
strokeWeight(random(5));
int lineX = int(random(760));
line(lineX, 480, lineX, 0);
}

if (cam.available() == true)
{
cam.read();
blend(cam,0,0,160,100,0,0,760,480,OVERLAY);
}
}


January 26, 2009

CTIN 405 - Sketch 1

Here's the code for my first sketch using Mobile Processing:

int[] sqrWidth = new int[5];
int[] sqrHeight = new int[5];
int letterX = 0;
int letterY = 0;
String str = "SIEHEHFBEICBT592483659234875290348578243075824ROISBHRKUSHBRSUBIRBUKUBHFKJHBSIQBIQRHBQO";

void setup()
{
sqrWidth[1] = 5;
sqrWidth[2] = 176;
letterX = random(width);
letterY = random(height);

background(255);
noStroke();
fill(0);

PFont font;
font = loadFont(FACE_SYSTEM, STYLE_PLAIN,SIZE_MEDIUM);
textFont(font);
textAlign(CENTER);
rectMode(CORNERS);
}

void draw()
{
background(random(255),random(255),random(255));

if(keyPressed)
{
letterX = random(width);
letterY = random(height);
}

char c[] = {str.charAt(random(85))};
String str2 = new String(c);

text(str2, letterX,letterY);

fill(random(255),random(255),random(255));
sqrWidth[1] = (sqrWidth[1] + 1) % 176;
sqrHeight[1] = pointerY;
rect(0,0,sqrWidth[1],sqrHeight[1]);

fill(random(255),random(255),random(255));
sqrWidth[2] = (sqrWidth[2] - 1) % 176;
sqrHeight[2] = pointerY;
rect(sqrWidth[2],sqrHeight[2],176,208);
}

January 29, 2009

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();
}

About January 2009

This page contains all entries posted to Logan Olson in January 2009. They are listed from oldest to newest.

December 2008 is the previous archive.

February 2009 is the next archive.

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

Powered by
Movable Type 3.31