FaceOCS – Portrait in a Flower
//
// 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
//
// This is an adapted version of the template by Swetha Kannan
import oscP5.*;
OscP5 oscP5;
/* @pjs preload= "happy.jpg"; */
PImage bg;
float petalColor = 255.0;
float petalColor2 = 140.0;
float petalColor3 = 140.0;
// num faces found
int found;
float cx, cy;
float secondsRadius;
// 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;
void setup() {
size(640, 480);
frameRate(30);
int radius = min(width, height) / 2;
secondsRadius = radius * 0.2;
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");
}
void draw() {
background(200);
stroke(0);
bg = loadImage("flowers.jpg");
image(bg, 0, 0);
image(bg, 0, 0, width, height);
if (found > 0) {
cx = width / 2;
cy = height - ((height -posePosition.y)/2);
//stem will grow along with pose position
stroke(19, 151, 37);
strokeWeight(10);
noFill();
float bexierX = width/2+(width/2-posePosition.x); // will control the curve of the stem
float bexier2X = width/2-(width/2-posePosition.x);
bezier(cx, cy, bexierX , cy, bexierX, height, width/2, height);
bezier(cx, posePosition.y, bexier2X, posePosition.y, bexier2X, cy, width/2, cy);
//Leaf will grow along with stem
pushMatrix();
stroke(19, 151, 37);
fill(19, 200, 37);
translate(width/2-15, cy-40);
print (int(posePosition.y/30));
drawLeaf(int(20-(posePosition.y/30)));
popMatrix();
if (eyebrowLeft >= 8.5) {
petalColor = random(0, 255);
petalColor2 = random(0, 255);
petalColor3 = random(0, 255);
}
//num of Petals will be dependant on how open mouth is
strokeWeight(10);
stroke(petalColor, petalColor2, petalColor3);
strokeWeight((height - posePosition.y)/10);
for (int petals = int(mouthHeight); petals>0; petals -=1) {
int maxPetals =petals;
float Spacing = TWO_PI / max;
line(cx, int(posePosition.y), cx + cos(petals)*secondsRadius, int(posePosition.y) + sin(petals)*secondsRadius);
}
//middle yellow of flower will grow along with posePosition
stroke(250, 200, 50);
strokeWeight((height - posePosition.y)/5);
point(width/2, posePosition.y);
}
}
// OSC CALLBACK FUNCTIONS
//drawLeaf function borrowed from Cath at https://openprocessing.orgsketch/7743
//Thankyou, I claim no responsibility
void drawLeaf(int shift) { // draw a leaf as follows
float pointShift = shift;
beginShape(); // start to draw a shape
vertex(20, 45); // begin at this point x, y
bezierVertex(30, 30, 60 + pointShift, 40 + pointShift/2, 70 + pointShift, 50);
bezierVertex(60 + pointShift, 55, 30, 65, 20, 45); // draw the other half of the shape
endShape();
}
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);
}
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) {
/* print the address pattern and the typetag of the received OscMessage */
println("#received an osc message");
println("Complete message: "+m);
println(" addrpattern: "+m.addrPattern());
println(" typetag: "+m.typetag());
println(" arguments: "+m.arguments()[0].toString());
if (m.isPlugged() == false) {
println("UNPLUGGED: " + m);
}
}
In this project, I was attempting to make a portrait of someone as a flower. The flower reacts to you and expresses itself in similar ways to you. When, you are slumping the flower is small but as you sit up straight, the flower grows as well. The stem gets taller, the leaf bigger and the flower itself larger. Similarly, if your mouth is closed only one petal will grow on the flower but with your mouth open multiple petals will begin to bloom. The movement of your eyebrows will also affect the color of the plant; in essence you can keep raising your eyebrows until you find a color that suits you. The tilt and movements of your head can also affect the curving of the flower stem. The flower is only as expressive as you, the user are. This project, although simple, carries a lot of what my visual clock did in that it is meant as an appreciation of nature, a landscape, and a scene. I am very happy with how the visuals of the project has turned out. I was able to create a working portrait of a flower that would mimics the user. I will probably go back to this project in order to create more depth in the flower and more customization options so that the flower will be an unmistakable portrait of someone.