Advertisement
Guest User

Untitled

a guest
Jul 1st, 2018
102
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None
  1. /*
  2.  
  3. PGraphics
  4.  
  5. State programming example
  6. Variation by Kasper Kamperman
  7.  
  8. state 1 = standby mode
  9. state 2 = attraction mode
  10. state 3 = active mode
  11.  
  12. The idea is that we make for each state (see tabs) a:
  13. - beginState function
  14. - updateState function
  15. - endState function
  16.  
  17. */
  18.  
  19.  
  20.  
  21. import processing.video.*;
  22.  
  23. Movie movie;
  24. Movie movie2;
  25.  
  26. long startTime = 0;
  27. int currentState = 1;
  28. int previousState = 0;
  29.  
  30. PImage[] camImageArray = new PImage[10];//[] maakt een array. new PImage[100] maakt een nieuwe array van 100 PImages aan.
  31. int camImgNr = 0;
  32. //Capture cam;
  33.  
  34. void settings() {
  35. size(640, 480);
  36. }
  37.  
  38. void setup(){
  39. frameRate(25);
  40.  
  41. arduinoSetup();
  42.  
  43. // preload movie when starting
  44. // we could this also in beginState2 but that gives a delay.
  45. movie = new Movie(this, "movie.mp4");
  46. movie2 = new Movie(this, "50.mp4");
  47.  
  48. //--------------------------
  49. bimg=loadImage("http://"+"lonelyplanet.es/img/uploads/images/senjo-ji-tokio.jpg");
  50. // bimg.resize(width, height);
  51. mmask=new int[640*480];
  52. //String[] cameras = Capture.list();
  53. //printArray(cameras);
  54. //---------------------------
  55. }
  56.  
  57. void draw(){
  58. //motionButtonDraw();
  59. // check if a state has changed (so current and previous are unequal !=)
  60. if(currentState != previousState) {
  61.  
  62. println("endState: "+previousState);
  63.  
  64. // we call the endState function of the now previousState
  65. switch(previousState) {
  66. case 1: endState1(); break;
  67. case 2: endState2(); break;
  68. case 3: endState3(); break;
  69. }
  70.  
  71. println("beginState: "+currentState);
  72.  
  73. // we call the beginState function of the now currentState
  74. switch(currentState) {
  75. case 1: beginState1(); break;
  76. case 2: beginState2(); break;
  77. case 3: beginState3(); break;
  78. }
  79.  
  80. // set the startTime of the currentState
  81. startTime = millis();
  82.  
  83. // make the currentState the previousState
  84. // we use this to detect if the currentState changes later again
  85. previousState = currentState;
  86. }
  87.  
  88. // on each draw we call updateState (for the currentState)
  89. // you can do this with a switch statement (like done above), but with
  90. // if/else it's possible the same (so use what you prefer yourself)
  91.  
  92. if(currentState == 1) {
  93. updateState1();
  94. }
  95. else if(currentState == 2) {
  96.  
  97. updateState2();
  98. }
  99. else if(currentState == 3) {
  100. updateState3();
  101. }
  102.  
  103. //switch(currentState) {
  104. // case 1: updateState1(); break;
  105. // case 2: updateState2(); break;
  106. // case 3: updateState3(); break;
  107. //}
  108.  
  109. }
Advertisement
RAW Paste Data Copied
Advertisement