import processing.opengl.*; import processing.serial.*; int x = 0, y = 0, prevX = mouseX, prevY = mouseY, radius = 0, kx, ky, pos; byte fillValue = 0, dFillValue = 1; PImage scrBuffer; float rval, gval, bval; float rsum = 0, gsum = 0, bsum = 0; boolean strokePending = false; int strokeInput[], xVector, yVector, xEntropy, yEntropy, translateVectorX, translateVectorY, translateStrokeX = 0, translateStrokeY = 0; byte[][][] ewStrokes = { { // b {0, 1} , {1, 0} , {-1, 0} }, { // c {-1, 0} , {0, 1} , {1, 0} }, { // d {0, 1} , {-1, 0} , {1, 0} }, { // e {1, 0} , {-1, 0} , {0, 1} , {1, 0} }, { // f {-1, 0} , {0, 1} }, { // g {-1, 0} , {1, 0} , {0, 1} , {-1, 0} }, { // i {0, 1} }, { // j {0, 1} , {-1, 0} }, { //l {0, 1} , {1, 0} }, { // o {-1, 0} , {0, 1} ,Ê{1, 0} , {0, -1} }, { // p {1, 0} , {-1, 0} , {0, 1} }, { // q {-1, 0} , {1, 0} ,Ê{0, 1} , {0, -1} }, { // r {0, -1} , {1, 0} }, { // t {1, 0} , {0, 1} }, { // u {0, 1} ,{1, 0} ,{0, -1} } }; char[] ewChars = { 'b', 'c', 'd', 'e', 'f', 'g', 'i', 'j', 'l', 'o', 'p', 'q', 'r', 't', 'u' }; int nEwChars = 15; int nStrokeBuffer = 0; byte xStrokeDir, yStrokeDir; String s = null, t; color c; Serial myPort; int maxStrokeBuffer = 20; byte[][] strokeBuffer = new byte[maxStrokeBuffer][2]; float v = 1.0/9.0; float[][] kernel = { { v, v, v }, { v, v, v }, { v, v, v } }; void setup() { size(600, 600, OPENGL); colorMode(RGB, 255); // size(400, 400); frameRate(30); smooth(); background(0); stroke(127); fill(fillValue+128); // point(200, 100); scrBuffer = createImage(width, height, RGB); randomSeed(2312); // println(Serial.list()); myPort = new Serial(this, "/dev/tty.usbserial-FTDOMKT5", 9600); myPort.clear(); strokeWeight(5); // strokeCap(ROUND); can't do these with openGL... // strokeJoin(ROUND); PFont font; // The font must be located in the sketch's // "data" directory to load successfully font = loadFont("TrebuchetMS-48.vlw"); textFont(font); textSize(72); } void draw() { if (strokePending) { stroke(0); strokeWeight(2); pushMatrix(); translate(width / 2, height / 2); translate(translateStrokeX, translateStrokeY); line(0, 0, 200 * xStrokeDir, 200 * yStrokeDir); translate(200 * xStrokeDir, 200 * yStrokeDir); translateStrokeX += 200 * xStrokeDir; translateStrokeY += 200 * yStrokeDir; if (yStrokeDir != 0) { line(0, 0, 15, 15 * -yStrokeDir); line(0, 0, -15, 15 * -yStrokeDir); } else if (xStrokeDir != 0) { line(0, 0, 15 * -xStrokeDir, 15); line(0, 0, 15 * -xStrokeDir, -15); } popMatrix(); strokeWeight(5); stroke(255); translate(translateVectorX, translateVectorY); line(0, 0, xVector / 8, yVector / 8); translateVectorX += xVector / 8; translateVectorY += yVector / 8; strokePending = false; } if (myPort.available() > 0) { s = myPort.readStringUntil('\n'); if (s != null) { s = s.trim(); if (s.equals("CAPTURE START")) { println("Started capturing..."); background(127); translateVectorX = width / 2; translateVectorY = height / 2; translateStrokeX = 0; translateStrokeY = 0; nStrokeBuffer = 0; } else if (s.equals("CAPTURE END")) { println("Ended capturing."); boolean foundEwMatch = false; for (int e = 0; e < nEwChars; e++) { if ((nStrokeBuffer == ewStrokes[e].length) && (!foundEwMatch)) { foundEwMatch = true; for (int buf = 0; buf < nStrokeBuffer; buf++) { for (int xy = 0; xy < 2; xy++) { if (strokeBuffer[buf][xy] != ewStrokes[e][buf][xy]) { foundEwMatch = false; } } } if (foundEwMatch) { char myChar = ewChars[e]; String myText = "" + myChar; println(myText); fill(255, 0, 0); text(myText, width / 2 + 10, height / 2 - 10); } } } } else { println(s); strokeInput = int(split(s.trim(), " ")); xVector = strokeInput[5]; yVector = -strokeInput[4]; println("x/y: " + (float)(xVector) / yVector); if (abs(xVector) > abs(yVector)) { yVector /= 4; yStrokeDir = 0; if (xVector > 0) { xStrokeDir = 1; } else { xStrokeDir = -1; } } else { xVector /= 4; xStrokeDir = 0; if (yVector > 0) { yStrokeDir = 1; } else { yStrokeDir = -1; } } /* xEntropy = strokeInput[5]; yEntropy = strokeInput[4]; */ strokePending = true; /* println("n: " + strokeInput[0]); println("nStroke: " + strokeInput[1]); */ strokeBuffer[nStrokeBuffer][0] = xStrokeDir; strokeBuffer[nStrokeBuffer][1] = yStrokeDir; nStrokeBuffer++; // println(strokeInput[3] + " " + strokeInput[4]); } // println(s); } } }