Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- PGraphics
- State programming example
- Variation by Kasper Kamperman
- state 1 = standby mode
- state 2 = attraction mode
- state 3 = active mode
- The idea is that we make for each state (see tabs) a:
- - beginState function
- - updateState function
- - endState function
- */
- import processing.video.*;
- Movie movie;
- Movie movie2;
- long startTime = 0;
- int currentState = 1;
- int previousState = 0;
- PImage[] camImageArray = new PImage[10];//[] maakt een array. new PImage[100] maakt een nieuwe array van 100 PImages aan.
- int camImgNr = 0;
- //Capture cam;
- void settings() {
- size(640, 480);
- }
- void setup(){
- frameRate(25);
- arduinoSetup();
- // preload movie when starting
- // we could this also in beginState2 but that gives a delay.
- movie = new Movie(this, "movie.mp4");
- movie2 = new Movie(this, "50.mp4");
- //--------------------------
- bimg=loadImage("http://"+"lonelyplanet.es/img/uploads/images/senjo-ji-tokio.jpg");
- // bimg.resize(width, height);
- mmask=new int[640*480];
- //String[] cameras = Capture.list();
- //printArray(cameras);
- //---------------------------
- }
- void draw(){
- //motionButtonDraw();
- // check if a state has changed (so current and previous are unequal !=)
- if(currentState != previousState) {
- println("endState: "+previousState);
- // we call the endState function of the now previousState
- switch(previousState) {
- case 1: endState1(); break;
- case 2: endState2(); break;
- case 3: endState3(); break;
- }
- println("beginState: "+currentState);
- // we call the beginState function of the now currentState
- switch(currentState) {
- case 1: beginState1(); break;
- case 2: beginState2(); break;
- case 3: beginState3(); break;
- }
- // set the startTime of the currentState
- startTime = millis();
- // make the currentState the previousState
- // we use this to detect if the currentState changes later again
- previousState = currentState;
- }
- // on each draw we call updateState (for the currentState)
- // you can do this with a switch statement (like done above), but with
- // if/else it's possible the same (so use what you prefer yourself)
- if(currentState == 1) {
- updateState1();
- }
- else if(currentState == 2) {
- updateState2();
- }
- else if(currentState == 3) {
- updateState3();
- }
- //switch(currentState) {
- // case 1: updateState1(); break;
- // case 2: updateState2(); break;
- // case 3: updateState3(); break;
- //}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement