//
// 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();
// gesture
float mouthHeight;
float mouthWidth;
float eyeLeft;
float eyeRight;
float eyebrowLeft;
float eyebrowRight;
float jaw;
float nostrils;
float circleX;
float circleY;
PImage starSky;
PImage aliens;
int score;
FloatList specialStars;
PFont fjFont;
int numOfStars;
boolean doneOnce;
void setup() {
size(800, 800);
frameRate(30);
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");
oscP5.plug(this, "mouthWidthReceived", "/gesture/mouth/width");
oscP5.plug(this, "mouthHeightReceived", "/gesture/mouth/height");
oscP5.plug(this, "eyeLeftReceived", "/gesture/eye/left");
oscP5.plug(this, "eyeRightReceived", "/gesture/eye/right");
oscP5.plug(this, "eyebrowLeftReceived", "/gesture/eyebrow/left");
oscP5.plug(this, "eyebrowRightReceived", "/gesture/eyebrow/right");
oscP5.plug(this, "jawReceived", "/gesture/jaw");
oscP5.plug(this, "nostrilsReceived", "/gesture/nostrils");
starSky = loadImage("stars.png");
aliens= loadImage("ALIENS.png");
score=0;
specialStars = new FloatList();
numOfStars=7;
for (int i=0; i<numOfStars;i++){ createSpecialStar(); } fjFont = createFont("FjallaOne-Regular.ttf",32); doneOnce=false; } public void createSpecialStar(){ float x= random(0,width); float y=random(85,height-180); specialStars.append(x); specialStars.append(y); } public void newSpecialStars(){ for (int i=specialStars.size()-1;i>-1; i--){
specialStars.remove(i);
}
for (int i=0; i<numOfStars; i++){
createSpecialStar();
}
}
void draw() {
image(starSky,0,0);
int seconds = second();
//refreshes special stars every 5 seconds
if ((seconds-1)%5==0 && doneOnce==true){
doneOnce=false;
}
if (seconds%5==0 &&doneOnce==false){
newSpecialStars();
doneOnce=true;
}
//tint(255,255,255);
float radius=40;
textFont(fjFont);
textSize(50);
text("Score: "+score,10,height-10);
fill(255,255,102);
noStroke();
//makes special stars
for (int i=0; i<specialStars.size(); i+=2){
float starX=specialStars.get(i);
float starY=specialStars.get(i+1);
ellipse(starX, starY, 10,10);
}
//Makes telescope Circle
stroke(0);
noFill();
stroke(204,229,255);
strokeWeight(4);
ellipse(circleX,circleY,radius*2,radius*2);
for (int i=0; i<specialStars.size(); i+=2){
float starX=specialStars.get(i);
float starY=specialStars.get(i+1);
//makes stars then checks valid to eat star
if (starX<circleX+(radius/2) && starX>circleX-(radius/2) && starY<circleY+(radius/2) && starY>circleY-(radius/2)){
if(jaw>23.5){
specialStars.remove(i+1);
specialStars.remove(i);
score+=1;
createSpecialStar();
}
}
}
if (eyebrowLeft>9.2){
image(aliens,width/6,height/4,592,326.5);
if (score<=5){ score=0; } else if (score>5){
score=score-5;
}
}
}
// 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);
circleX=x+(posePosition.x-150);
circleY=y+(posePosition.y-150);
}
public void poseOrientation(float x, float y, float z) {
println("pose orientation\tX: " + x + " Y: " + y + " Z: " + z);
poseOrientation.set(x, y, z);
}
public void mouthWidthReceived(float w) {
println("mouth Width: " + w);
mouthWidth = w;
}
public void mouthHeightReceived(float h) {
println("mouth height: " + h);
mouthHeight = h;
}
public void eyeLeftReceived(float f) {
println("eye left: " + f);
eyeLeft = f;
}
public void eyeRightReceived(float f) {
println("eye right: " + f);
eyeRight = f;
}
public void eyebrowLeftReceived(float f) {
println("eyebrow left: " + f);
eyebrowLeft = f;
}
public void eyebrowRightReceived(float f) {
println("eyebrow right: " + f);
eyebrowRight = f;
}
public void jawReceived(float f) {
println("jaw: " + f);
jaw = f;
}
public void nostrilsReceived(float f) {
println("nostrils: " + f);
nostrils = f;
}
// all other OSC messages end up here
void oscEvent(OscMessage m) {
if(m.isPlugged() == false) {
println("UNPLUGGED: " + m);
}
} |