Created
December 5, 2015 14:28
-
-
Save tmshv/582f5de862a692e8c89e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import processing.serial.*; | |
import processing.video.*; | |
Serial port; | |
String portName; | |
Movie actionMovie; | |
Movie defaultMovie; | |
Movie movie; | |
int showCounter = 100; | |
int counter = 0; | |
int state = 0; | |
String[] texts; | |
int textIndex; | |
int DEFAULT_STATE = 0; | |
int ACTION_STATE = 1; | |
void setup() { | |
fullScreen(P3D); | |
portName = Serial.list()[1]; | |
port = new Serial(this, portName, 9600); | |
texts = loadStrings(""); | |
defaultMovie = new Movie(this, ""); | |
defaultMovie.loop(); | |
actionMovie = new Movie(this, ""); | |
actionMovie.loop(); | |
showDefault(); | |
} | |
void draw(){ | |
int val = port.available() > 0 ? port.read() : 0; | |
if(val == 1 && counter == 0){ | |
showAction(); | |
} | |
if(state == DEFAULT_STATE) drawDefault(); | |
if(state == ACTION_STATE) drawAction(); | |
} | |
void drawDefault(){ | |
drawMovie(); | |
} | |
void drawAction(){ | |
counter --; | |
if(counter == 0){ | |
showDefault(); | |
return; | |
} | |
drawMovie(); | |
translate(width/2, height/2); | |
String m = texts[textIndex]; | |
fill(0); | |
textSize(30); | |
textAlign(CENTER, CENTER); | |
text(m, 0, 0); | |
} | |
void showAction(){ | |
state = ACTION_STATE; | |
counter = showCounter; | |
textIndex = (int) random(texts.length); | |
movie = actionMovie; | |
movie.jump(0); | |
} | |
void showDefault(){ | |
state = DEFAULT_STATE; | |
movie = defaultMovie; | |
movie.jump(0); | |
} | |
void drawMovie(){ | |
if (movie.available() == true) { | |
movie.read(); | |
} | |
image(movie, 0, 0, width, height); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment