Collaborative coding and creation

School was out this Monday and Tuesday as a result of the Columbus Day holiday which they evidently take very seriously here in New England. Nonetheless I had to work at the Equipment Room, which meant that I had to report to an empty campus and work on an almost empty floor. I say almost because this is ITP, even when the floor is closed the floor is never empty. I ran into my coworker Mark Kleback and Phan Visutyothapibal who were working on a piece of code for a collaborative project. They had decided to “shoot” text out of the screen at the viewer in a matter that resembled the cosmic rays shooting through the universe in this frame from 2001: A Space Odessey:

Cosmic Ray Scene from 2001 Space Odyssey
Cosmic Ray Scene from 2001 Space Odyssey

They asked for my help and I began looking through their code and rewriting parts of it and together in the course of a couple hours we managed this piece of code which as you can see creates an array of objects which creates another array of objects and shoots them out of the screen one by one. I’m still waiting to see how they use the code in their final project (which I hear will be interfacing with MaxMSP) but I’m glad of our little collaboration.

I’m only posting the source code since this seems to break in Processing.js. Take a look:

String phraseStrings[] = {
"Hello there", "How are you"
};
PhraseObj[] phraseObjects;
PFont fontA;
int incrementer = 0;
int curPhrase = 0;

void setup() {

size(600, 600, P3D);
background(0);

fontA = loadFont("AndaleMono-48.vlw");
phraseObjects = new PhraseObj[phraseStrings.length];
for (int i = 0; i < phraseStrings.length; i++) { phraseObjects[i] = new PhraseObj(phraseStrings[i]); } frameRate(24); } void draw() { background(0); translate(width/2, height/2); rotateX(PI/4); for (int i = 0; i < phraseObjects.length; i++) { if (phraseObjects[i].enabled) { phraseObjects[i].drawPhrase(); } } } void mousePressed() { phraseObjects[curPhrase].start(); curPhrase++; for (int i = 0; i < phraseObjects.length; i++) { for (int j = 0; j < phraseObjects[i].curChars.length; j++) { println(phraseObjects[i].curChars[j].charStr); } } if (curPhrase >= phraseObjects.length) {
curPhrase = 0;
}
}

class CharObj {
String charStr;

float x, y, z, xD, yD, zD;
int fontSize;
PFont font;
boolean enabled;

CharObj(String _charStr, float _xD, float _yD, float _zD) {
charStr = _charStr;
x = 0;
y = 0;
z = 0;
xD = _xD;
yD = _yD;
zD = _zD;
font = loadFont("AndaleMono-48.vlw");
fontSize = 48;
enabled = false;
}

void start() {
// RESET VARIABLES TO START
x = 0;
y = 0;
z = 0;
enabled = true;
}

void charDraw() {
textFont(fontA);
fill(255);
textSize(fontSize);
text(charStr, x, y, z);
x += xD;
y += yD;
z += zD;
}
}
class PhraseObj {
String phraseStr;
boolean enabled;
CharObj[] curChars;
int incrementer = 0;
int frameNumber = 10;

PhraseObj(String _phraseStr) {
phraseStr = _phraseStr;
curChars = new CharObj[phraseStr.length()];
float tempX = random(-15,15);
float tempY = random(-15,15);
float tempZ = 5;
// Create Array of CharObjs
for (int i = 0; i < phraseStr.length() ; i++ ) { char temp = phraseStr.charAt(i); curChars[i] = new CharObj(Character.toString(temp), tempX, tempY, tempZ); } enabled = false; } void start() { enabled = true; incrementer = 0; } void drawPhrase() { if ((incrementer % frameNumber == 0) && (incrementer / frameNumber < curChars.length)) { int charNum = incrementer / frameNumber; curChars[charNum].start(); println("Character " + curChars[charNum].charStr + " enabled"); } for (int i = 0; i < curChars.length; i++) { if (curChars[i].enabled) { curChars[i].charDraw(); } } incrementer++; } }

Author: Ali

Developer and dreamer. I like to solve problems and make things come to life.

Leave a Reply

Your email address will not be published. Required fields are marked *