Skip to content

Instantly share code, notes, and snippets.

@krclark
Created October 14, 2016 12:36
Show Gist options
  • Save krclark/f70c2e3c9c4108c0f1bea7575bec181e to your computer and use it in GitHub Desktop.
Save krclark/f70c2e3c9c4108c0f1bea7575bec181e to your computer and use it in GitHub Desktop.
// Processing 3.0x template for receiving raw points from
// Kyle McDonald's FaceOSC v.1.1
// https://github.com/kylemcdonald/ofxFaceTracker
//
// Adapted by Kaleb Crawford, 2016, after:
// 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
// https://gist.github.com/1603230
import java.io.FileReader;
import java.io.File;
import oscP5.*;
OscP5 oscP5;
int found;
float[] rawArray;
int highlighted; //which point is selected
char[] textArray;
int[] textPosArray = new int[650*2];
PImage img;
int w = 640;
int h = 480;
//--------------------------------------------
void setup() {
size(640, 480);
frameRate(30);
oscP5 = new OscP5(this, 8338);
oscP5.plug(this, "found", "/found");
oscP5.plug(this, "rawData", "/raw");
img = loadImage("parchment.jpg");
//copy text from .txt file into array
String[] newstringarray = loadStrings("actualtext.rtf");
String text = newstringarray[8];
//print(text);
int margin = 5;
int neww = w-margin*2;
int newh = h+margin*4+150;
int txtrows = 30;
int txtcols = 45;
textArray = text.toCharArray();
print(textArray.length);
for (int index = 0; index <= 649*2; index+=2) {
int row = (index/2)/txtrows;
int col = (index/2)%txtrows;
int y = row*(newh/txtrows);
int x = col*(neww/txtcols);
textPosArray[index] = x;
textPosArray[index+1] = y;
}
}
//--------------------------------------------
void draw() {
color c = color(50, 47, 20, 255);
background(255);
//noStroke();
image(img, 0, 0);
PFont cursive = createFont("Nightingale", 32);
textFont(cursive);
//find the average of the left eye
int eye_lx_av = 0;
int eye_ly_av = 0;
//average left x val
for (int lx = 72; lx <= 82; lx+=2) {
eye_lx_av+=rawArray[lx];
}
//average left y val
for (int ly = 73; ly <= 83; ly+=2) {
eye_ly_av+=rawArray[ly];
}
eye_lx_av = eye_lx_av/6;
eye_ly_av = eye_ly_av/6;
//draws a circle approximately where eye would be
float midx1 = rawArray[34];
float midy1 = rawArray[35];
float line_x1 = midx1-10;
float line_y1 = midy1+20;
float line_x2 = midx1+20;
float line_y2 = midy1-10;
float midx2 = rawArray[42];
float midy2 = rawArray[43];
float line_x3 = midx2+20;
float line_y3 = midy2+5;
float line_x4 = midx2-20;
float line_y4 = midy2-5;
noFill();
stroke(c);
strokeJoin(MITER);
//line(line_x1, line_y1, line_x2, line_y2);
//line(line_x3, line_y3, line_x4, line_y4);
//bezier(line_x1, line_y1, line_x2, line_y2, line_x4, line_y4, line_x3, line_y3);
//bezier(line_x1, line_y1, line_x2+5, line_y2+10, line_x4-5, line_y4+10, line_x3, line_y3);
//ellipse(eye_lx_av, eye_ly_av, abs(rawArray[78] - rawArray[72])+5, abs(rawArray[75]-rawArray[83])+10);
//find the average of the right eye
int eye_rx_av = 0;
int eye_ry_av = 0;
//average right x val
for (int rx = 84; rx <= 94; rx+=2) {
eye_rx_av+=rawArray[rx];
}
//average right y val
for (int ry = 85; ry <= 95; ry+=2) {
eye_ry_av+=rawArray[ry];
}
eye_rx_av = eye_rx_av/6;
eye_ry_av = eye_ry_av/6;
//draws a circle approximately where eye would be
//ellipse(eye_rx_av, eye_ry_av, abs(rawArray[84] - rawArray[90])+5, abs(rawArray[89]-rawArray[93])+10);
//find the average of the mouth
int mouth_x = 0;
int mouth_y = 0;
//average right x val
for (int mx = 96; mx <= 118; mx+=2) {
mouth_x+=rawArray[mx];
}
//average right y val
for (int my = 97; my <= 119; my+=2) {
mouth_y+=rawArray[my];
}
mouth_x = mouth_x/12;
mouth_y = mouth_y/12;
//draws a circle approximately where eye would be
//ellipse(mouth_x, mouth_y, abs(rawArray[96] - rawArray[108])+5, abs(rawArray[104]-rawArray[113])+10);
for (int index = 0; index <= 649*2; index+=2) {
int tSize = 11;
float changeFact = random(-3, 2);
fill(c);
int x=textPosArray[index]+10;
int y=textPosArray[index+1]+20;
//increases eye size as eye gets closer to text
if (abs(eye_lx_av-x) < (abs(rawArray[78] - rawArray[72])+5)) {
if (abs(eye_ly_av-y) < (abs(rawArray[75]-rawArray[83]))+10) {
changeFact = ((abs(rawArray[75]-rawArray[83])+10))-abs(eye_ly_av-y);
tSize+=changeFact/4;
}
} if (abs(eye_rx_av-x) < (abs(rawArray[84] - rawArray[90])+5)) {
if (abs(eye_ry_av-y) < (abs(rawArray[89]-rawArray[93]))+10) {
changeFact = ((abs(rawArray[89]-rawArray[93])+10))-abs(eye_ry_av-y);
tSize+=changeFact/4;
}
} if (abs(mouth_x-x) < (abs(rawArray[96] - rawArray[108])+5)/2) {
if (abs(mouth_y-y) < (abs(rawArray[104]-rawArray[113])+10)/2) {
changeFact = ((abs(rawArray[104]-rawArray[113])+10))-abs(mouth_y-y);
changeFact = changeFact/5;
tSize+=changeFact/4;
}
}
textSize(tSize);
text(textArray[index/2], x-(changeFact/4), y-(changeFact/4));
}
if (found != 0) {
if (rawArray != null) {
/*for (int val = 0; val < rawArray.length -1; val+=2) {
if (val == highlighted) {
fill(255, 0, 0);
} else {
fill(100);
}
ellipse(rawArray[val], rawArray[val+1], 8, 8);
}
} else {
fill(0); */
}
}
}
//--------------------------------------------
public void found(int i) {
// println("found: " + i);
found = i;
}
public void rawData(float[] raw) {
rawArray = raw; // stash data in array
}
//--------------------------------------------
void keyPressed() {
if (keyCode == RIGHT) {
highlighted = (highlighted + 2) % rawArray.length;
}
if (keyCode == LEFT) {
highlighted = (highlighted - 2) % rawArray.length;
if (highlighted < 0) {
highlighted = rawArray.length-1;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment