//Samia Ahmed, samiaa@andrew.cmu.edu
//A reproduction of Text Rain by Camille Utterback
//Carnegie Mellon University: 51-482
//January 2011
import processing.video.*;
Capture capture;
char poem[][] = {{'I', ' ', 'l', 'i', 'k', 'e', ' ', 't', 'a', 'l', 'k', 'i', 'n', 'g', ' ', 'w', 'i', 't', 'h', ' ', 'y', 'o', 'u', ',' },
{'s', 'i', 'm', 'p', 'l', 'y', ' ', 't', 'h', 'a', 't', ':', ' ', 'c', 'o', 'n', 'v', 'e', 'r', 's', 'i', 'n', 'g', ',' }};
int poemLength = 24;
int position[][] = new int[2][poemLength];
int speed[][] = new int[2][poemLength];
color captureColor;
void setup() {
size(640, 480);
background(0, 0, 0);
capture = new Capture(this, width, height, 30);
//sets the speed at which the letters drop, and initial position
for (int i = 0; i < 2; i++){
for (int k = 0; k < poemLength; k++){
speed[i][k] = int(random(4, 10));
}
}
}
void draw() {
pushMatrix();
scale(-1.0, 1.0);
image(capture, -capture.width, 0);
filter(GRAY);
popMatrix();
for (int i = 0; i < 2; i++){
for (int k = 0; k < poemLength; k++){
//these set when the red and blue texts are predominant
if (i == 0 && (second() > 0 && second() < 35)){
if(millis()%100 == 0)
position[i][k] = -1000;
}
if (i == 1 && (second() > 30 || second() < 5)){
if (millis()%100 == 0)
position[i][k] = -1000;
}
captureColor = get(width/poemLength*k+(width/poemLength), position[i][k]+speed[i][k]);
//moving the letters
if (position[i][k] > height || random(1000) > 990) //out of bounds, and random deletion
position[i][k] = -30;
else if (position[i][k]+speed[i][k] >= height || position[i][k] < speed[i][k] || red(captureColor) > 100) //legal moves
position[i][k] = position[i][k]+speed[i][k];
else {
while(red(get(width/poemLength*k+(width/poemLength), position[i][k]-speed[i][k])) < 100 && position[i][k] > 0) //jumping out of black
position[i][k] = position[i][k]-speed[i][k];
}
if (i == 0){
fill(255, 0, 0);
text(poem[i][k], width/(poemLength+2)*k+width/poemLength*2.5, position[i][k]);
}
else if (i == 1){
fill(0, 0, 255);
text(poem[i][k], width/(poemLength+2)*k+width/poemLength, position[i][k]);
}
}
}
}
void captureEvent(Capture capture) {
capture.read();
} |