Skip to content

Instantly share code, notes, and snippets.

@yz3440
Created November 7, 2018 04:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yz3440/a67b77fc9c145891f4fdda9af1de1c38 to your computer and use it in GitHub Desktop.
Save yz3440/a67b77fc9c145891f4fdda9af1de1c38 to your computer and use it in GitHub Desktop.
FaceOSC and Generative Pattern
import oscP5.*;
OscP5 oscP5;
int found;
float mouthHeight;
float rotateX, rotateY, rotateZ;
float eyeL, eyeR;
boolean paused = false;
boolean frameTaken = false;
int x = 0;
int y = 0;
int r = 1;
int sizes[] = new int[]{1, 2, 5, 10, 20, 40, 50, 100};
int speed = abs(r);
int count = 0;
float xoff1 = 0.0;
float xoff2 = 0.2;
float xoff3 = 0.6;
int step = 1;
void setup() {
size(1000, 1000, P3D);
background(0);
frameRate(60);
noStroke();
oscP5 = new OscP5(this, 8338);
oscP5.plug(this, "found", "/found");
oscP5.plug(this, "mouthHeight", "/gesture/mouth/height");
oscP5.plug(this, "poseOrientation", "/pose/orientation");
oscP5.plug(this, "eyeLeft", "/gesture/eye/left");
oscP5.plug(this, "eyeRight", "/gesture/eye/right");
}
void draw() {
if (found != 0) {
pushMatrix();
translate(width/2, height/2, -500-frameCount%10*100);
rotateX(rotateX);
rotateY(rotateY);
rotateZ(rotateZ);
r = sizes[(int)random(sizes.length)];
//r =1;
//}
if (mouthHeight < 1.5) {
step = 0;
paused = true;
} else {
frameTaken = false;
step = (int) random(map(mouthHeight, 0, 7, 1, 40));
//background(0,0,0,255);
}
if (paused && !frameTaken) {
//saveFrame("frames/####.png");
frameTaken = true;
}
//r = sizes[frameCount%sizes.length];
for (int i = 0; i<step; i++) {
float R = noise(xoff1) * 256;
float G = noise(xoff2) * 256;
float B = noise(xoff3) * 256;
if (x <= width & y <= height) {
if (x >= width | x < 0) {
y += r;
x -= width;
}
fill(R, G, B, 170);
rect(x - width/2, y - height/2, r, r);
rect(y - width/2, x - height/2, r, r);
rect(height/2-y-r, width/2-x-r, r, r);
rect(width/2-x-r, height/2-y-r, r, r);
x += r;
} else {
x=0;
y=0;
}
xoff1 += .01;
xoff2 += .03;
xoff3 += .05;
}
popMatrix();
} else {
background(0);
}
}
public void found(int i) {
found = i;
}
public void mouthHeight(float h) {
mouthHeight = h;
}
public void poseOrientation(float x, float y, float z) {
//println("pose orientation\tX: " + x + " Y: " + y + " Z: " + z);
rotateX = -x * 2;
rotateY = y * 2;
rotateZ = -z * 2;
}
public void eyeLeft(float l) {
eyeL = l;
}
public void eyeRight(float l) {
eyeR = l;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment