Processing code

import processing.serial.*;
Serial myPort;

//sound
import ddf.minim.*;
Minim minim;
AudioInput in;
float loudness;

float cm ;
float motiondetect=1;
float x, y, c1, c2, c3, z, s;
float convertString;

String[] fontT = new String[4];
String word;

//park
static String [] wordInput1 = {
“Scary”, “Relaxing”, “Fun”, “Leaves”, “Birds”, “Trees”,
“Wind”, “Lights”, “Play”, “Laughter”, “Romance”,”Raining”
};
//Study Room
static String [] wordInput2 = {
“Assignment”, “Exams”, “tired”, “holiday”, “tomorrow”,
“hungry”, “sleepy”, “boring”, “learning”, “GPA”, “Parents”, “1986176540”
};
//CMC
static String [] wordInput3 = {
“Experiment”, “Art”, “Project”, “Creativity”, “Friends”, “Professors”,
“Pacific Cafe”, “Coffee”, “24Hours”, “Mac”, “Final Cut”, “Animation”, “Editing”,
“Script”, “Programming”, “Photography”, “SAMSON”, “Daniel”
};
//Street
static String [] wordInput4 = {
“Noisy”, “Crossing”, “Hurry”, “LKF”, “Taxi”, “Festival Walk”, “Appointment”,
“Home”, “Waiting”, “Meeting”, “MTR”, “Tomorrow”
};
//canteen
static String [] wordInput5 = {
“Hungry”, “Drink”, “Friends”, “Relaxing”, “Noisy”, “spaghetti”,
“coke”, “fries”, “chatting”, “Noodles”, “Discussion”, “Ramen”, “Chopsticks”
};
PFont f1, f2, f3, f4;
float theta;
int w=1;

void setup() {
size(displayWidth, 800);
colorMode(HSB, 360, 100, 100);
myPort = new Serial(this, Serial.list()[4], 9600);

minim = new Minim(this);
in = minim.getLineIn();

f1 = loadFont(“ArcadeBook-250.vlw”);
f2 = loadFont(“BlackoakStd-48.vlw”);
f3 = loadFont(“ImprintMT-Shadow-48.vlw”);
f4 = loadFont(“LucidaBlackletter-200.vlw”);
}

void serialEvent(Serial myPort) {

String inString = myPort.readStringUntil(‘\n’); // get string until line breaker

if (inString != null) {
inString = trim(inString);

float[] readings = float(split(inString, ‘,’));

if (readings.length >=2)
{
motiondetect = readings[0];
cm = map(readings[1], 0, 100, 0, 30);
}
}

println(“motion= “+motiondetect+” cm=”+cm);
}

void draw() {

String[] fontT = {
“f1”, “f2”, “f3”, “f4”
};

fill(0, 0, 100, 15);
rect(0, 0, width, height);

//sound
line(0, height/2, displayWidth, height/2);
line(0, height/2+2, displayWidth, height/2+2);
line(0, height/2-2, displayWidth, height/2-2);
for (int i = 0; i < in.bufferSize() -1; i++)
{
line(i+150, height/2 + in.mix.get(i)*400, i+151, height/2 + in.mix.get(i+1)*400);
}

stroke(0, 80, 100);
loudness=map(in.mix.level(), 0, 0.5, 0, 100);
println(loudness);

//word generater
if (w==1) word=wordInput1[floor(random(0, wordInput1.length))];
else if (w==2) word=wordInput2[floor(random(0, wordInput2.length))];
else if (w==3)word=wordInput3[floor(random(0, wordInput3.length))];
else if (w==4)word=wordInput4[floor(random(0, wordInput4.length))];
else word=wordInput5[floor(random(0, wordInput5.length))];

textAlign(CENTER);
if (motiondetect == 0) {

fill(c1, c2, c3);

x= random(0, width);
y= random(0, height);
c1= random(0, 360);
c2= random(loudness*3, loudness*4);
c3= random(0, 100);
s= random(0+cm, 230-cm);
z= random(1, 10);

textFont(f1, s);
text(word, x, y, z);

rotate(theta);
theta += 4;
}

if (motiondetect ==1 && frameCount%20==0 ) {

fill(c1, c2, c3);
x= random(0, width);
y= random(0, height);
c1= random(0, 360);
c2= random(loudness, loudness*4);
c3= random(0, 100);
s= random(0+cm, 230-cm);
z= random(1, 10);
textFont(f1, s);
text(word, x, y, z);
}
}

void keyReleased() {
if (key ==’ ‘)
{
if (w<5) w++;
else w=1;
}
}

boolean sketchFullScreen()
{
return true;
}

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

Advertisements
%d bloggers like this: