Skip to content

Instantly share code, notes, and snippets.

@narner
Last active July 24, 2017 08:19
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 narner/0e521f9d42aaa54a71816864b6a1e135 to your computer and use it in GitHub Desktop.
Save narner/0e521f9d42aaa54a71816864b6a1e135 to your computer and use it in GitHub Desktop.
import processing.net.*; // include the networking library
Server server; // will receive predictions
String messageText;
PFont f;
void setup()
{
fullScreen(P3D);
frameRate(600);
server = new Server(this, 5204); // listen on port 5204
messageText = "";
textAlign(CENTER);
fill(255);
f = createFont("Arial",48,true); // Arial, 16 point, anti-aliasing on
textFont(f, 120);
}
void draw()
{
// check for incoming data
Client client = server.available();
if (client != null) {
// check for a full line of incoming data
String line = client.readStringUntil('\n');
if (line != null) {
println(line);
int val = int(trim(line)); // extract the predicted class
println(val);
if (val == 1) {
messageText = "Val 1";
} else if (val == 2) {
messageText = "Val 2D";
} else if (val == 3) {
messageText = "Val 3";
}
}
}
// draw
background(0);
text(messageText, width/2, height/2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment