compositor for 2d glitch effects
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. Capture cam;
  2. Movie movie;
  3. boolean moviePlaying;
  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. source = img.get();
  34. fallbackImage = source;
  35. nativeResoX = source.width;
  36. nativeResoY = source.height;
  37. println(nativeResoX);
  38. }
  39. void fallback() {
  40. println("Fallback");
  41. setImage(fallbackImage); //fallbackImage should always be a copy of the last image that worked
  42. }
  43. void update() {
  44. if (source == null) {
  45. fallback();
  46. }
  47. int toW, toH;
  48. if (source.width > source.height) {
  49. toW = renderSize;
  50. toH = int(map(source.height, 0, source.width, 0, renderSize));
  51. } else {
  52. toW = int(map(source.width, 0, source.height, 0, renderSize));
  53. toH = renderSize;
  54. }
  55. toW = (toW % 2 == 0) ? toW : toW+1;
  56. toH = (toH % 2 == 0) ? toH : toH+1;
  57. renderer.setSize(toW, toH);
  58. }
  59. // This function returns all the files in a directory as an array of Strings
  60. String[] listFileNames(String dir) {
  61. File file = new File(dir);
  62. if (file.isDirectory()) {
  63. String names[] = file.list();
  64. return names;
  65. } else {
  66. return null;
  67. }
  68. }
  69. String dir;
  70. String[] selection;
  71. int selId;
  72. void importURI(String path) {
  73. File file = new File(path);
  74. if (file.isDirectory()) {
  75. dir = path;
  76. String names[] = file.list();
  77. ArrayList<String> usableFiles = new ArrayList<String>();
  78. for (int i = 0; i < names.length; i++) {
  79. if (isImage(names[i]) || isVideo(names[i])) {
  80. usableFiles.add(names[i]);
  81. }
  82. }
  83. selection = new String[usableFiles.size()];
  84. for (int i = 0; i < usableFiles.size(); i++) selection[i] = usableFiles.get(i);
  85. println("Got new selection from folder. " + selection.length + " usable files.");
  86. path = dir + "/" + selection[(int)random(selection.length)];
  87. }
  88. if (isImage(path) || isVideo(path)) {
  89. println("Importing file " + path);
  90. if (moviePlaying) movie.stop();
  91. if (isImage(path)) {
  92. moviePlaying = false;
  93. setImage(loadImage(path));
  94. } else if (isVideo(path)) {
  95. moviePlaying = true;
  96. newMovie(path);
  97. movie.loop();
  98. movie.volume(0);
  99. }
  100. }
  101. }
  102. }