compositor for 2d glitch effects
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. Capture cam;
  2. Movie movie;
  3. boolean moviePlaying, imageChanged;
  4. PImage fallbackImage;
  5. void movieEvent(Movie m) {
  6. if (moviePlaying) {
  7. m.read();
  8. //if mode = 1..
  9. sourceManager.setImage(movie.get());
  10. //movie.jump(random(movie.duration())); //??
  11. }
  12. }
  13. void newMovie(String path) {
  14. movie = new Movie(this, path);
  15. }
  16. boolean isVideo(String path) {
  17. String fpl = path.toLowerCase();
  18. if (fpl.endsWith(".mp4") || fpl.endsWith(".avi") || fpl.endsWith(".webm") || fpl.endsWith(".mkv") || fpl.endsWith(".mov")) return true;
  19. else return false;
  20. }
  21. boolean isImage(String path) {
  22. String fpl = path.toLowerCase();
  23. if (fpl.endsWith(".bmp") || fpl.endsWith(".png") || fpl.endsWith(".jpg") || fpl.endsWith(".jpeg") || fpl.endsWith(".gif")) return true; //gif = special case!
  24. else return false;
  25. }
  26. class SourceManager { //no constructor
  27. void setSource() { //set source to renderer
  28. renderer.beginDraw();
  29. renderer.image(source, 0, 0, renderer.width, renderer.height);
  30. renderer.endDraw();
  31. }
  32. void setImage(PImage img) { //set image to source
  33. imageChanged = true;
  34. source = img.get();
  35. fallbackImage = source;
  36. nativeResoX = source.width;
  37. nativeResoY = source.height;
  38. println(nativeResoX);
  39. }
  40. void fallback() {
  41. println("Fallback");
  42. setImage(fallbackImage); //fallbackImage should always be a copy of the last image that worked
  43. }
  44. void update() {
  45. if (source == null) {
  46. fallback();
  47. }
  48. int toW, toH;
  49. if (source.width > source.height) {
  50. toW = renderSize;
  51. toH = int(map(source.height, 0, source.width, 0, renderSize));
  52. } else {
  53. toW = int(map(source.width, 0, source.height, 0, renderSize));
  54. toH = renderSize;
  55. }
  56. toW = (toW % 2 == 0) ? toW : toW+1;
  57. toH = (toH % 2 == 0) ? toH : toH+1;
  58. renderer.setSize(toW, toH);
  59. }
  60. // This function returns all the files in a directory as an array of Strings
  61. String[] listFileNames(String dir) {
  62. File file = new File(dir);
  63. if (file.isDirectory()) {
  64. String names[] = file.list();
  65. return names;
  66. } else {
  67. return null;
  68. }
  69. }
  70. String dir;
  71. String[] selection;
  72. int selId;
  73. void importURI(String path) {
  74. File file = new File(path);
  75. if (file.isDirectory()) {
  76. dir = path;
  77. String names[] = file.list();
  78. ArrayList<String> usableFiles = new ArrayList<String>();
  79. for (int i = 0; i < names.length; i++) {
  80. if (isImage(names[i]) || isVideo(names[i])) {
  81. usableFiles.add(names[i]);
  82. }
  83. }
  84. selection = new String[usableFiles.size()];
  85. for (int i = 0; i < usableFiles.size(); i++) selection[i] = usableFiles.get(i);
  86. println("Got new selection from folder. " + selection.length + " usable files.");
  87. path = dir + "/" + selection[(int)random(selection.length)];
  88. }
  89. if (isImage(path) || isVideo(path)) {
  90. println("Importing file " + path);
  91. if (moviePlaying) movie.stop();
  92. if (isImage(path)) {
  93. moviePlaying = false;
  94. setImage(loadImage(path));
  95. } else if (isVideo(path)) {
  96. moviePlaying = true;
  97. newMovie(path);
  98. movie.loop();
  99. movie.volume(0);
  100. }
  101. }
  102. }
  103. }