Spiel für das Medientheater HBK Saar, Teil des Projektes "Fun Palace" (Reupload der Repository von 2017)
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

wordedImage.pde 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import processing.video.*;
  2. PApplet app; //technically needed to create movie instances inside of a class
  3. PImage blob;
  4. boolean debug = false; //new: activate it to see the movies in the background
  5. WordedImageLayer[] layers = new WordedImageLayer[7];
  6. void movieEvent(Movie m) {
  7. m.read();
  8. }
  9. void setup() {
  10. size(1536, 230);
  11. textAlign(CENTER);
  12. fill(255);
  13. blob = loadImage("blob.png");
  14. app = this;
  15. /* new:
  16. you don't need to load the movie seperately from the layer-class anymore. it loads the video itself now yay :) just give the filename as first argument.
  17. (changed first argument from Movie-type to String-type, added movie constructor to class)
  18. */
  19. layers[0] = new WordedImageLayer(
  20. "0.mov", //String, the name of the movie file we want to load in.
  21. "word", //String, the word it should use to write over the movie.
  22. 0, //Integer, horizontal X-position. vertical position doesn't matter, the videos are always stretched over the whole height
  23. 10, //Integer, brightness-threshold. look up what a threshold is if you don't know it. min: 0, max: 255. if it's 30 it will write the word for every pixel in the video that is less bright than 30
  24. 15 //Integer, level of detail. the higher the number, the less detail
  25. );
  26. layers[1] = new WordedImageLayer("1.mov", "door", 1000, 40, 3);
  27. layers[2] = new WordedImageLayer("2.mov", "a", 0, 10, 10); //new: make threshold a negative number to inverse it.
  28. layers[3] = new WordedImageLayer("3.mov", "water", 0, 10, 4);
  29. layers[4] = new WordedImageLayer("4.mov", "wave", 0, 100, 20);
  30. layers[5] = new WordedImageLayer("5.mov", "smoke", 0, 200, 7);
  31. layers[6] = new WordedImageLayer("6.mov", "smoke", 0, 200, 7);
  32. /* new functions:
  33. startPlaying, stopPlaying, togglePlaying
  34. */
  35. layers[0].startPlaying();
  36. // layers[1].startPlaying();
  37. // layers[2].startPlaying();
  38. // layers[3].startPlaying();
  39. // layers[4].startPlaying();
  40. // layers[5].startPlaying();
  41. }
  42. void draw() {
  43. background(0);
  44. for (int i = 0; i < layers.length; i++) {
  45. layers[i].update();
  46. }
  47. }
  48. void mousePressed() {
  49. for (int i = 0; i < layers.length; i++) {
  50. if (layers[i].hover()) {
  51. println("Clicked layer " + i + "!");
  52. //you could call the following function with a button. (are there really going to be buttons in final version?)
  53. layers[i].togglePlaying();
  54. }
  55. }
  56. }
  57. class WordedImageLayer {
  58. Movie sourceMovie;
  59. PGraphics canvas;
  60. PImage getmov;
  61. PImage mov;
  62. String word;
  63. String movFileName;
  64. boolean inverse;
  65. boolean hover;
  66. boolean isPlaying;
  67. int threshold;
  68. int detailfactor;
  69. int movX;
  70. int movY = 0;
  71. int movW;
  72. int movH;
  73. WordedImageLayer(String MovName, String Word, int X, int thresh, int Factor) {
  74. movFileName = MovName;
  75. word = Word;
  76. movX = X;
  77. threshold = thresh;
  78. detailfactor = Factor;
  79. sourceMovie = new Movie(app, movFileName);
  80. }
  81. void startPlaying() { //new-
  82. sourceMovie.loop();
  83. isPlaying = true;
  84. }
  85. void stopPlaying() { //-functions-
  86. sourceMovie.stop();
  87. isPlaying = false;
  88. }
  89. void togglePlaying() { //-yay!
  90. if (isPlaying)
  91. stopPlaying();
  92. else
  93. startPlaying();
  94. }
  95. boolean hover() {
  96. if (mouseX > movX && mouseX < movX + movW && mouseY > movY && mouseY < movY + movH)
  97. return true;
  98. else
  99. return false;
  100. }
  101. void update() {
  102. if (isPlaying) { //new! check if isplaying. so you can just keep the for loops that update every video. it will break here if the video shall not be running.
  103. try {
  104. mov = sourceMovie.get();
  105. mov.resize(0, height);
  106. movW = mov.width;
  107. movH = mov.height;
  108. canvas = createGraphics(movW, movH);
  109. canvas.beginDraw();
  110. canvas.imageMode(CORNER);
  111. canvas.image(mov, 0, 0, canvas.width, canvas.height);
  112. canvas.imageMode(CENTER);
  113. canvas.image(blob, mouseX-movX, mouseY, height/3, height/3);
  114. mov = canvas.get();
  115. canvas.endDraw();
  116. mov.resize(0, height/detailfactor);
  117. if (debug) {
  118. tint(255, 60);
  119. image(canvas, movX, 0);
  120. tint(255, 255);
  121. }
  122. mov.loadPixels();
  123. for (int i=0; i<mov.pixels.length; i++ ) {
  124. int col = mov.pixels[i];
  125. if (brightness(col) > threshold) {
  126. //int x = i%mov.width*detailfactor;
  127. int x = int(map(i%mov.width*detailfactor, 0, mov.width, 0, movW/detailfactor)); //new! fixes a bug where the cursor was out of place
  128. int y = i/mov.width*detailfactor+10;
  129. text(word, x+movX, y);
  130. }
  131. }
  132. }
  133. catch (Exception e) {
  134. }
  135. }
  136. }
  137. }