// display text, classify emotion, move // mpurver import processing.net.*; import liblinear.*; import controlP5.*; ControlP5 controlP5; String textValue = ""; Textfield myTextfield; int iSector = 0; int nSector = 6; float sectorAngle = TWO_PI / 6.0; int centreX; int centreY; int radius = 150; color sectorColour = color(50,200,0); color lineColour = color(100); color textColour = color(255,255,255); color sentenceColour = color(255); BufferedWriter logger; Calendar calendar = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); int pause = 0; int p = 0; int waitSpins = 6; int ws = waitSpins; boolean running = false; boolean gotResult = false; String lastSent = ""; String sent = ""; double[] classes = null; String[] emotions = new String[] { "happy", "anger", "fear", "sad", "surprise", "disgust" }; int bg = 0; Client httpClient; Classifier svm; String installDir = "http://www.eecs.qmul.ac.uk/~mpurver/WoE"; //String installDir = "/Users/toby/Desktop/WheelOfEmotion"; void setup() { size(600, 400, JAVA2D); centreX = width/2; centreY = height/2; PFont font = createFont("Arial-BoldMT", 24); textFont(font); textAlign(CENTER); svm = new Classifier(installDir, emotions); frameRate(20); background(bg); stroke(lineColour); smooth(); controlP5 = new ControlP5(this); // controlP5.setControlFont(createFont("Arial-BoldMT",12)); myTextfield = controlP5.addTextfield("sentence",10,height-50,200,20); myTextfield.setFocus(true); myTextfield.keepFocus(true); if (!installDir.startsWith("http:")) { try { logger = new BufferedWriter( new FileWriter( new File(installDir, "log.txt"), true ) ); loggit("NEW RUN"); } catch (Exception e) { e.printStackTrace(); System.exit(0); } } } void draw() { // are we pausing? if (p > 0) { p--; println("pausing"); controlP5.draw(); return; } // if it's new, classify and start new display if (!sent.equals(lastSent)) { println("new sentence"); loggit("NEW SENTENCE [" + sent + "]"); running = true; gotResult = false; // classify classes = classify(sent); loggit("CLASSES " + Arrays.toString(classes)); p = pause; ws = waitSpins; } else { //println("old sentence"); } // clear background background(bg); //text(sent,centreX,centreY); // draw circle if (!sent.isEmpty()) { float startAngle = 0; float endAngle = sectorAngle; for (int iS = 0; iS 0) { ws--; } } lastSent = sent; } strokeWeight(1); controlP5.draw(); } private int getColour(int iS) { if (ws > 0) { // waiting to build tension, so just light up current sector ... if (iS == iSector) { return sectorColour; } else { return bg; } } else { // we're ready, so display results from classifier if (classes[iS]>0) { return sectorColour; } else { return bg; } } } private float getAlpha(int iS) { if ((ws > 0) || (classes[iS]<=0)) { return 255; } else { return 255*(float)classes[iS]; } } private boolean fake = false; private double[] classify(String s) { double[] l = new double[emotions.length]; if (fake) { for (int i=0; i 1 double max = 0.0; for (int i=0; i l[i] ? max : l[i] ); println("got data " + emotions[i] + " " + i + " " + l[i]); } if (max > 1.0) { for (int i=0; i