arialy-faceosc
When thinking about a concept for the face tracker, I was more interested in how the tracker would control something other than a face. Rather than use the movements of the face to control something, I wanted to control something with the lack of movement.
import processing.sound.*;
SoundFile file;
Amplitude amp;
int dim;
int stillEnough = 0;
float vol = 0;
float thinness = 0;
float moonX = 525;
Particle[] particleList = new Particle[50];
int count = 0;
float globalRMS = map(.15, 0, .3, 0, 20);
//
// a template for receiving face tracking osc messages from
// Kyle McDonald's FaceOSC https://github.com/kylemcdonald/ofxFaceTracker
//
// 2012 Dan Wilcox danomatika.com
// for the IACD Spring 2012 class at the CMU School of Art
//
// adapted from from Greg Borenstein's 2011 example
// http://www.gregborenstein.com/
// https://gist.github.com/1603230
//
import oscP5.*;
OscP5 oscP5;
// num faces found
int found;
// pose
float poseScale;
PVector posePosition = new PVector();
PVector poseOrientation = new PVector();
void setup() {
dim = width/2;
size(640, 480);
frameRate(30);
for (int o = 0; o<particleList.length; o++) { particleList[o] = new Particle(); } // Load a soundfile from the /data folder of the sketch and play it back file = new SoundFile(this, "portTown.mp3"); amp = new Amplitude(this); oscP5 = new OscP5(this, 8338); oscP5.plug(this, "found", "/found"); oscP5.plug(this, "poseScale", "/pose/scale"); oscP5.plug(this, "posePosition", "/pose/position"); oscP5.plug(this, "poseOrientation", "/pose/orientation"); } class Particle { PVector position; PVector velocity; float offset = random(-7, 1); Particle() { position = new PVector(width/2, height/2); velocity = new PVector(1 * random(-1, 1), -1 * random(-1, 1)); } void update() { // Add the current speed to the position. position.add(velocity); if (position.x > width) {
position.x = 0;
}
if (position.x < 0) { position.x = width; } if ((position.y > height) || (position.y < 0)) { velocity.y = velocity.y * -1; } } void display() { // Display circle at x position //stroke(200); fill(255, 255, 224, thinness); ellipse(position.x, position.y, globalRMS+offset, globalRMS+offset); ellipse(position.x, position.y, (globalRMS+offset)*.5, (globalRMS+offset)*.5); } } void drawGradient(float x, float y, float r, float g, float b) { for (float ra = x*.75; ra > 0; ra -= 3) {
fill(r, g, b);
ellipse(x, y, width*1.5, ra);
r = (r - 2) % 360;
b = (b-.5) % 360;
g = (g -2)%360;
}
}
int still() {
if (posePosition.x < width/2 + 50 && posePosition.x > width/2 -50) {
return 1;
} else {
return 0;
}
}
void draw() {
background(0);
fill(255);
ellipse(moonX, 75, 70, 70);
fill(0);
ellipse(moonX + 15, 75, 50, 50);
rectMode(CORNERS);
noStroke();
fill(0, 100, 0, 200);
rect(0, height/1.4, width, height);
fill(0, 191, 255);
drawGradient(width/2, height*.99, 0, 191, 255);
//ellipse(width/2, height * .92, width *1.5, height/3);
if (still() == 1) {
if (thinness < 150) {
thinness +=10;
}
println("hi");
if (vol == 0) {
file.play();
amp.input(file);
}
if (vol < 1) { vol+= .001; file.amp(vol); } float rms = amp.analyze(); float mapRMS = map(rms, 0, .3, 10, 25); globalRMS = mapRMS; } else { if (vol > 0) {
vol-= .01;
file.amp(vol);
}
}
if (posePosition.x > width/2 +50) {
for (int m = 0; m<particleList.length; m++) { if (particleList[m] != null) { particleList[m].position.x -=2; } } if (thinness > 0) {
thinness -=10;
}
moonX -=1;
}
if (posePosition.x < width/2 -50) {
for (int n = 0; n<particleList.length; n++) { if (particleList[n] != null) { particleList[n].position.x +=2; } } if (thinness > 0) {
thinness -=10;
}
moonX += 1;
}
for (int o = 0; o<particleList.length; o++) { if (particleList[o] != null) { particleList[o].update(); particleList[o].display(); } if (found > 0) {
//translate(posePosition.x, posePosition.y);
//scale(poseScale);
noFill();
rectMode(CENTER);
fill(255, 255, 255, 20);
ellipse(posePosition.x, posePosition.y, 16, 16);
}
}
}
// OSC CALLBACK FUNCTIONS
public void found(int i) {
//println("found: " + i);
found = i;
}
public void poseScale(float s) {
//println("scale: " + s);
poseScale = s;
}
public void posePosition(float x, float y) {
//println("pose position\tX: " + x + " Y: " + y );
posePosition.set(x, y, 0);
}
public void poseOrientation(float x, float y, float z) {
//println("pose orientation\tX: " + x + " Y: " + y + " Z: " + z);
poseOrientation.set(x, y, z);
}
// all other OSC messages end up here
void oscEvent(OscMessage m) {
if (m.isPlugged() == false) {
//println("UNPLUGGED: " + m);
}
}