Created
February 28, 2014 17:54
-
-
Save wstucco/9276076 to your computer and use it in GitHub Desktop.
Processing.org state machine
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
interface State { | |
public State nextState(); | |
} | |
class IdleState implements State { | |
public State nextState() { | |
return new ScanState(); | |
} | |
} | |
class ScanState implements State { | |
public State nextState() { | |
return new LookupState(); | |
} | |
} | |
class LookupState implements State { | |
public State nextState() { | |
return new MessageState(); | |
} | |
} | |
class MessageState implements State { | |
public State nextState() { | |
return new PauseState(); | |
} | |
} | |
class PauseState implements State { | |
private int start; | |
private final int timeout = 5000; // 5 sec | |
PauseState() { | |
start = millis(); | |
} | |
public State nextState() { | |
if((millis()-start) < timeout) | |
return this; | |
return new IdleState(); | |
} | |
} | |
State state; | |
void setup() { | |
frameRate(1); | |
state = new IdleState(); | |
} | |
void draw() { | |
println(state); | |
state = state.nextState(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment