Processing Code: ‘Hairy Ball’

import oscP5.*;
import netP5.*;
import ddf.minim.*;
NetAddress myRemoteLocation1;
NetAddress myRemoteLocation2;
NetAddress myRemoteLocation3;
int cuantos = 3000;//change the density of the hair
Pelo[] lista ;
float[] z = new float[cuantos];
float[] phi = new float[cuantos];
float[] largos = new float[cuantos];
float radio;
float rx = 0;
float ry =0;
boolean checkPlay=false;
Minim minim;
AudioPlayer player;

float excitement=0.8;
float engagement=0.6;
float frustration=0.4;
float meditation=0.2;
float boredom=0;
float lastExcitement;
float lastEngagement;
float lastFrustration;
float lastMeditation;
float lastBoredom;
int excount=0;
int encount=0;
int fcount=0;
int mcount=0;
int bcount=0;
int allcount=1500;//change the time for monitoring the value change of data

OscP5 oscP5;

int angle;

void setup() {
oscP5 = new OscP5(this, 7400);
minim = new Minim(this);
player = minim.loadFile(“WhiteNoiseSmall.aif”);

myRemoteLocation1 = new NetAddress(“172.20.187.146”,5001);
myRemoteLocation2 = new NetAddress(“172.20.187.146”,5001);
myRemoteLocation3 = new NetAddress(“172.20.187.146”,5001);

size(displayWidth, displayHeight, P3D);
radio = 150;//can change the size of the hariball
lista = new Pelo[cuantos];
for (int i=0; i<cuantos; i++) {//drawing the hair
lista[i] = new Pelo();
}
noiseDetail(3);//change the sharpness of the display
}

void draw() {

noCursor();

print(“excitement=”+excitement+”\n”);
print(“engagement=”+engagement+”\n”);
print(“frustration=”+frustration+”\n”);
print(“meditation=”+meditation+”\n”);
print(“boredom=”+boredom+”\n”);
print(“excount=”+excount+”\n”);
print(“encount=”+encount+”\n”);
print(“fcount=”+fcount+”\n”);
print(“mcount=”+mcount+”\n”);
print(“bcount=”+bcount+”\n”);
excitement=excitement+0.0001;
engagement=engagement+0.0005;
frustration=frustration+0.001;
meditation=meditation+0.0015;
//boredom=boredom+0.002;

if(mousePressed==false){ // create an osc message
OscMessage myMessage = new OscMessage(“/test”);

println(meditation+”-“+frustration+”-“+engagement+”-“+excitement+”-“+boredom);
myMessage.add(meditation);
myMessage.add(frustration);
myMessage.add(engagement);
myMessage.add(excitement);
myMessage.add(boredom);
// send the message
oscP5.send(myMessage, myRemoteLocation1);
oscP5.send(myMessage, myRemoteLocation2);
oscP5.send(myMessage, myRemoteLocation3);
}

background(0);

//Text field for monitoring the data values
textSize(20);
fill(255);

text(“EXCITEMENT “+excitement, width-250, height-100);
text(“ENGAGEMENT “+engagement, width-250, height-80);
text(“FRUSTRATION “+frustration, width-250, height-60);
text(“MEDITATION “+meditation, width-250, height-40);
text(“BOREDOM “+boredom, width-250, height-20);
translate(width/2, height/2);//P3D set up
//here is to count the time that any parameter does not change indicating the headset is not working
if (excitement==lastExcitement) {
excount++;
if (excount>allcount) {
excount=allcount+1;
}
}
if (engagement==lastEngagement) {
encount++;
if (encount>allcount) {
encount=allcount+1;
}
}
if (frustration==lastFrustration) {
fcount++;
if (fcount>allcount) {
fcount=allcount+1;
}
}
if (meditation==lastMeditation) {
mcount++;
if (mcount>allcount) {
mcount=allcount+1;
}
}
if (boredom==lastBoredom) {
bcount++;
if (bcount>allcount) {
bcount=allcount+1;
}
}

if (excitement!=lastExcitement) {
excount=0;
}
if (engagement!=lastEngagement) {
encount=0;
}
if (frustration!=lastFrustration) {
fcount=0;
}
if (meditation!=lastMeditation) {
mcount=0;
}
if (boredom!=lastBoredom) {
bcount=0;
}

lastExcitement=excitement;
lastEngagement=engagement;
lastFrustration=frustration;
lastMeditation=meditation;
lastBoredom=boredom;

if (excount>allcount||encount>allcount||fcount>allcount||mcount>allcount||bcount>allcount) {

//here is the effect of TV noise when the headset is not working properly
//reference: www.openprocessing.org/sketch/24107
translate(-width/2, -height/2);
for (int i=width; i>=0; i-=4) {
for (int j=width; j>=0; j-=4) {
fill(random(255));
rect(i, j, 4, 4);
noStroke();
}
}
if(checkPlay==false){
minim = new Minim(this);
player = minim.loadFile(“WhiteNoiseSmall.aif”);
player.play();
checkPlay=true;
}
}
else {
checkPlay=false;
player.close();
minim.stop();
if (boredom>engagement && boredom>frustration && boredom> meditation&& boredom> excitement) {
//ADD YOUR effect FOR BOREDOM HERE
rotateY(0);
rotateX(0);
fill(0);
noStroke();
radio = height/4*boredom;
sphere(radio);

for (int i = 0;i < cuantos; i++) {
lista[i].dibujar();
}
}

if (excitement>engagement && excitement>frustration && excitement> meditation&& excitement>boredom) {

rotateY(radians(0));
rotateX(radians(0));
fill(0);
radio = height/4*excitement; //no more scaling *excitement
noStroke();
sphere(radio);

for (int i = 0;i < cuantos; i++) {
lista[i].dibujar();
}
}

if (engagement>excitement && engagement>frustration && engagement>meditation&&engagement>boredom) {

angle++;//angle needs to be set 360=0
if(angle==360){angle=0;}
rotateY(radians(angle));//ball can spin and rotate
rotateX(radians(angle));
radio = height/4*engagement; //no more scaling *engagement
fill(0);
noStroke();
sphere(radio);

for (int i = 0;i < cuantos; i++) {
lista[i].dibujar();
}
}

if (frustration>excitement && frustration>engagement && frustration>meditation && frustration>boredom) {

float rxp = ((random(150, 450)-(width/2))*0.005);//ball can fluctuate
float ryp = ((random(150, 450)-(height/2))*0.005);
rx = (rx*0.9)+(rxp*0.1);
ry = (ry*0.9)+(ryp*0.1);
rotateY(rx);
rotateX(ry);
radio = height/4*frustration; //no more scaling *frustration
fill(0);
noStroke();
sphere(radio);

for (int i = 0;i < cuantos; i++) {
lista[i].dibujar();
}
}

if (meditation>excitement && meditation>engagement && meditation>frustration&& meditation>boredom) {

rotateY(radians(0));
rotateX(radians(0));
fill(0);
noStroke();
radio = height/4*meditation; //no more scaling *meditation
sphere(radio);

for (int i = 0;i < cuantos; i++) {
lista[i].dibujar();
}
}
}
}
class Pelo {

float z = random(-radio, radio);
float phi = random(TWO_PI);
float largo = random(1.15, 1.2);//control the length of the hair
float theta = asin(z/radio);

void dibujar() {//grow hair

if (meditation>excitement && meditation>engagement && meditation>frustration &&meditation>boredom&& excount<allcount && encount<allcount && fcount<allcount && mcount<allcount&&bcount<allcount) {
float largo = random(1.15, 1.2);//control the length of the hair
float off = (random(millis()* 0.0005, sin(phi))-0.5) * 0.6;//enable the hair looks vivid can change noise to random to acheive falling effect
float offb = (random(millis() * 0.0007, sin(z) * 0.01)-0.5) * 0.6;//enable the hair looks vivid can change noise to random to acheive falling effect
float thetaff = theta+off;
float phff = phi+offb;
float x = radio * cos(theta) * cos(phi);
float y = radio * cos(theta) * sin(phi);
float z = radio * sin(theta);
float xo = radio * cos(thetaff) * cos(phff);
float yo = radio * cos(thetaff) * sin(phff);
float zo = radio * sin(thetaff);
float xb = xo * largo*1;//by mutiple >1 can change the length of each hair
float yb = yo * largo*1;//by mutiple >1 can change the length of each hair
float zb = zo * largo*1;//by mutiple >1 can change the length of each hair
beginShape(LINES);//drawing lines
//strokeWeight(2);
stroke(0);
vertex(x, y, z);
stroke(230,200);
vertex(xb, yb, zb);
endShape();
}

else if (excitement>engagement && excitement>frustration && excitement> meditation &&excitement>boredom&& excount<allcount && encount<allcount && fcount<allcount && mcount<allcount&&bcount<allcount) {
float largo = random(1.2, 1.35);//control the length of the hair
float off = (noise(millis()* 0.0005, sin(phi))-0.5) * 0.3;//enable the hair looks vivid can change noise to random to acheive falling effect
float offb = (noise(millis() * 0.0007, sin(z) * 0.01)-0.5) * 0.3;//enable the hair looks vivid can change noise to random to acheive falling effect
float thetaff = theta+off;
float phff = phi+offb;
float x = radio * cos(theta) * cos(phi);
float y = radio * cos(theta) * sin(phi);
float z = radio * sin(theta);
float xo = radio * cos(thetaff) * cos(phff);
float yo = radio * cos(thetaff) * sin(phff);
float zo = radio * sin(thetaff);
float xb = xo * largo*1;//by mutiple >1 can change the length of each hair
float yb = yo * largo*1;//by mutiple >1 can change the length of each hair
float zb = zo * largo*1;//by mutiple >1 can change the length of each hair
beginShape(LINES);//drawing lines
//strokeWeight(4);
stroke(255);
vertex(x, y, z);
stroke(150,100);
vertex(xb, yb, zb);
endShape();
}

else {
float off = (noise(millis()* 0.0005, sin(phi))-0.5) * 0.3;//enable the hair looks vivid can change noise to random to acheive falling effect
float offb = (noise(millis() * 0.0007, sin(z) * 0.01)-0.5) * 0.3;//enable the hair looks vivid can change noise to random to acheive falling effect
float thetaff = theta+off;
float phff = phi+offb;
float x = radio * cos(theta) * cos(phi);
float y = radio * cos(theta) * sin(phi);
float z = radio * sin(theta);
float xo = radio * cos(thetaff) * cos(phff);
float yo = radio * cos(thetaff) * sin(phff);
float zo = radio * sin(thetaff);
float xb = xo * largo*1;//by mutiple >1 can change the length of each hair
float yb = yo * largo*1;//by mutiple >1 can change the length of each hair
float zb = zo * largo*1;//by mutiple >1 can change the length of each hair
beginShape(LINES);//drawing lines
// strokeWeight(2);
stroke(255);
vertex(x, y, z);
stroke(150,100);
vertex(xb, yb, zb);
endShape();
}
}
}

 

void oscEvent(OscMessage theOscMessage) {
// check if theOscMessage has an address pattern we are looking for
if(theOscMessage.checkAddrPattern(“/AFF/Excitement”) == true) {
// parse theOscMessage and extract the values from the OSC message arguments
//excitement = ceil(theOscMessage.get(0).floatValue()*255);
excitement = theOscMessage.get(0).floatValue();
} else if (theOscMessage.checkAddrPattern(“/AFF/Meditation”) == true) {
meditation =theOscMessage.get(0).floatValue();
}
if(theOscMessage.checkAddrPattern(“/AFF/Engaged/Bored”) == true) {
// parse theOscMessage and extract the values from the OSC message arguments

engagement = theOscMessage.get(0).floatValue();
boredom = 1-engagement; //to seperate boredom from engagement
//println(“ENTERED”);
} else if (theOscMessage.checkAddrPattern(“/AFF/Frustration”) == true) {
frustration = theOscMessage.get(0).floatValue();
}
}