Permalink
Browse files

Created state machine to handle displays and users and adding image p…

…rocessing code now. Will need 2.0a5 or later to compile.
  • Loading branch information...
1 parent 6cf5e48 commit f64b0b1526d33260935076e3d3054faf1930ca32 @johnbentcope committed May 22, 2012
Showing with 103 additions and 8 deletions.
  1. +1 −0 PreviewBox.pde
  2. +4 −2 Scanner.pde
  3. +59 −0 StateMachine.pde
  4. +39 −6 TagBot.pde
  5. BIN data/Creepster-Regular-48.vlw
  6. BIN data/DilleniaUPCBold-32.vlw
View
@@ -18,6 +18,7 @@ class PreviewBox {
}
public void makeIt(String orientation){
+ noFill();
if (orientation == "landscape") {
rect(width/2, height/2, high, wide);
} else {
View
@@ -18,10 +18,12 @@ class Scanner {
return webcam;
}
- public PImage crushWebcam(PImage webcam) {
+ public PImage crushWebcam(PImage webcam, PreviewBox previewBox) {
webcam.loadPixels();
int len = webcam.pixels.length;
-
+ for ( int i = 0; i < len ; i++ ) {
+ webcam.pixels[i] = color(green(webcam.pixels[i]), blue(webcam.pixels[i]), red(webcam.pixels[i]));
+ }
webcam.updatePixels();
return webcam;
}
View
@@ -0,0 +1,59 @@
+class StateMachine {
+
+ int state = 0;
+ String stateString = "Strike a pose!";
+
+ public int globalState() {
+ return state;
+ }
+
+ public boolean setState(int newstate) {
+ state = newstate;
+ return true;
+ }
+
+ public boolean aButton() {
+ if ( state == 0 ) {
+ state = 1;
+ return true;
+ } else {
+ state = 0;
+ return true;
+ }
+ }
+
+ public boolean dButton() {
+ state = 2;
+ return true;
+ }
+
+ public boolean makeLogo() {
+ fill(#FF0088);
+ textAlign(RIGHT);
+ textFont(creepster);
+ text("TAG", width-10, 48);
+ text("BOT", width-10, 88);
+ return true;
+ }
+
+ public boolean displayState() {
+ fill(#FF0088);
+ textAlign(RIGHT);
+ textFont(dillenia);
+ switch (state) {
+ case 0 :
+ stateString = "Strike a pose!";
+ break;
+ case 1 :
+ stateString = "Preview";
+ break;
+ case 2:
+ stateString = "State 3";
+ break;
+ }
+
+ text(stateString, width-10, height-10);
+ return true;
+ }
+
+}
View
@@ -4,11 +4,15 @@ import processing.video.*;
/*** INSTANTIALIZINATE SOME OBJECTS ***/
PImage imgBase;
PImage imgScanned;
+PFont creepster;
+PFont dillenia;
Capture webcam;
PreviewBox previewBox;
Canvas canvas;
Robot robot;
Scanner scanner;
+StateMachine stateMachine;
+
int prevMargin = 50; //makes setting margins simpler
@@ -21,7 +25,6 @@ int prevMargin = 50; //makes setting margins simpler
void setup() {
size(640, 480);
rectMode(CENTER);
- noFill();
frameRate(15);
String[] cameras = Capture.list();
@@ -50,6 +53,11 @@ void setup() {
robot = new Robot(500, 1);
scanner = new Scanner();
+
+ stateMachine = new StateMachine();
+ dillenia = loadFont("DilleniaUPCBold-32.vlw");
+ creepster = loadFont("Creepster-Regular-48.vlw");
+
}
@@ -58,17 +66,42 @@ void draw() {
if (webcam.available() == true) {
webcam.read();
//image(webcam, 0, 0);
- image(scanner.crushWebcam(webcam), 0, 0);
+ imgBase = scanner.getWebcam(webcam);
}
- previewBox.makeIt(canvas.getOrientation());
+
+ // 0 is straight webcam
+ // 1 is crushed webcam preview
+ // 2 is proof of design
+
+ switch (stateMachine.globalState()) {
+ case 0:
+ image(imgBase, 0, 0);
+ previewBox.makeIt(canvas.getOrientation());
+ break;
+ case 1:
+ image(scanner.crushWebcam(imgBase, previewBox),0 ,0 );
+ previewBox.makeIt(canvas.getOrientation());
+ break;
+ case 2:
+ break;
+ }
+ stateMachine.makeLogo();
+ stateMachine.displayState();
}
void keyPressed() {
switch (key) {
- case 's':
- canvas.flipsOrientation() ;
- break;
+ case 's' :
+ canvas.flipOrientation();
+ break;
+ case 'a' :
+ stateMachine.aButton();
+ break;
+ case 'd' :
+ stateMachine.dButton();
+ break;
}
+
}
Binary file not shown.
View
Binary file not shown.

0 comments on commit f64b0b1

Please sign in to comment.