compositor for 2d glitch effects
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

source.pde 3.0KB

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