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.

manglr2.pde 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /* todo:
  2. - implement all sox effects
  3. - don't rerender on change of blend-mode
  4. - add blending option everywhere
  5. - add blend-effect to blend a selected layer
  6. - add png corruption
  7. - add png, jpg, gif and fractal compression artifact effects
  8. */
  9. import drop.*;
  10. import controlP5.*;
  11. import java.util.*;
  12. //import processing.net.*;
  13. import java.awt.event.KeyEvent;
  14. import java.awt.event.KeyListener;
  15. import processing.video.*;
  16. import com.hamoid.*;
  17. import java.io.*;
  18. import java.util.Arrays;
  19. Class<?> sketchClass;
  20. VideoExport videoExport;
  21. int maxFx = 15; //possible amount of effect layers
  22. SDrop drop;
  23. PImage source;
  24. PGraphics renderer;
  25. PImage viewport;
  26. SourceManager sourceManager;
  27. String frameName; //to save frame as image
  28. int uptime; //logs how many frames this software has rendered before (inaccurate, it's actually way, way more)
  29. boolean recording; //save every frame?
  30. int renderSize = 500; //px
  31. float renderFrameRate;
  32. String[] saveData;
  33. String OS;
  34. int w, h;
  35. boolean spawnPlaying = false;
  36. boolean autoPlay = false;
  37. boolean videoRecord = false;
  38. //boolean webcamMode = false;
  39. String[] params;
  40. PImage droppedImage;
  41. void dropEvent(DropEvent theDropEvent) {
  42. sourceManager.importURI(theDropEvent.filePath());
  43. }
  44. SecondApplet gui;
  45. PApplet mainApplet;
  46. void setup() {
  47. mainApplet = this;
  48. sketchClass = getClass();
  49. println(sketchClass);
  50. size(800, 600);
  51. w = width;
  52. h = height;
  53. frameRate(60);
  54. surface.setResizable(true);
  55. surface.setLocation(570, 240);
  56. noSmooth(); //saves resources but makes sum look shiddy
  57. imageMode(CENTER);
  58. drop = new SDrop(this);
  59. saveData = loadStrings(dataPath("saves.sav"));
  60. println("Loading Savefile...");
  61. for (int i = 0; i < saveData.length; i ++) {
  62. String[] temp;
  63. if (saveData[i].contains("uptime")) {
  64. temp = split(saveData[i], " = ");
  65. uptime = int(temp[1]);
  66. println("Uptime: " + uptime);
  67. }
  68. }
  69. fallbackImage = loadImage(dataPath("0.png"));
  70. bin = loadImage(dataPath("bin.png"));
  71. String[] cameras = Capture.list();
  72. cam = new Capture(this, 1920,1080, "pipeline:autovideosrc");
  73. //falls du nicht mit mir in die oper möchtest gehe ich mit pe, sie hat morgen abend keine termine und würde sich natürlich in beiden fällen freuen. von ihr auch noch alles gute zum geburtstag hatte ich vergessen zu sagen.
  74. //ich bin auch aufgeregt. vielleicht doch lieber mit dem zug. einfach versuchen sich einfach was zu gönnen. zu deinem schwarzen kleid ziehe ich
  75. OS = getOS();
  76. String[] args = {"SecondFrame"};
  77. //gui = new SecondApplet(this);
  78. gui = new SecondApplet();
  79. PApplet.runSketch(args, gui);
  80. renderer = createGraphics(width, height);
  81. renderer.noSmooth();
  82. viewport = createImage(renderer.width, renderer.height, ARGB);
  83. sourceManager = new SourceManager();
  84. //sourceManager.importURI("/home/giers/.local/bin/fast-style-transfer/data/train2014");
  85. }
  86. PImage webcamImg;
  87. void captureEvent(Capture c) {
  88. c.read();
  89. webcamImg = cam.get();
  90. }
  91. void draw() {
  92. uptime+=1;
  93. renderFrameRate = frameRate;
  94. //if(webcamRunning){
  95. //webcamImg =
  96. // }
  97. background(255);
  98. sourceManager.update(); //will write some image to the renderer
  99. sourceManager.setSource();
  100. if (autoPlay) gui.robot();
  101. gui.shaderManager.applyShader(); //boolean animate (iterative calcs), boolean apply (draw)
  102. background(color(0));
  103. viewport = renderer.get();
  104. int imgw, imgh;
  105. if (renderer.width < renderer.height) {
  106. imgh = height;
  107. imgw = int((float(renderer.width)/float(renderer.height))*height);
  108. } else {
  109. imgw = width;
  110. imgh = int(width/(float(renderer.width)/float(renderer.height)));
  111. if (imgh > height) {
  112. imgh = height;
  113. imgw = int((float(renderer.width)/float(renderer.height))*height);
  114. }
  115. }
  116. image(viewport, width/2, height/2, imgw, imgh);
  117. if (videoRecord) {
  118. videoExport.saveFrame();
  119. fill(#ff0000);
  120. ellipse(width-100, height-100, 30, 30);
  121. }
  122. if (recording) {
  123. snapshot();
  124. fill(#ff0000);
  125. ellipse(width-100, height-100, 30, 30);
  126. }
  127. }
  128. void snapshot() {
  129. frameName = str(uptime);
  130. renderer.save(dataPath("")+"/snapshots/" + frameName + ".png");
  131. saveData[1] = "uptime = " + frameName;
  132. println("Rendered " + frameName + ".png at " + dataPath("")+"/snapshots/ with a resolution of " + renderer.width + " x " + renderer.height);
  133. saveStrings(dataPath("saves.sav"), saveData);
  134. }
  135. void mousePressed()
  136. {
  137. if (mouseButton == LEFT) {
  138. if (sourceManager.dir != null) {
  139. sourceManager.importURI(sourceManager.dir + "/" + sourceManager.selection[(int)random(sourceManager.selection.length)]);
  140. }
  141. }
  142. if (mouseButton == RIGHT) {
  143. snapshot();
  144. }
  145. }
  146. void mouseWheel(MouseEvent event) {
  147. if (event.getCount() < 0) renderSize += 8;
  148. else renderSize -= 8;
  149. renderSize = constrain(renderSize, 8, 15000);
  150. }
  151. String getOS() {
  152. String os = System.getProperty("os.name");
  153. if (os.contains("Windows")) {
  154. return "windows";
  155. } else if (os.contains("Mac")) {
  156. return "mac";
  157. } else if (os.contains("Linux")) {
  158. return "linux";
  159. } else {
  160. return "other";
  161. }
  162. }
  163. /*
  164. boolean runCommand(String[] command) {
  165. //String returnedValues;
  166. try {
  167. Process p = new ProcessBuilder(command).start();
  168. int ii = p.waitFor();
  169. if (ii == 0) { //success signal
  170. //BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
  171. //while ( (returnedValues = stdInput.readLine ()) != null) {
  172. //println(returnedValues);
  173. //}
  174. return(true);
  175. } else {
  176. //BufferedReader stdErr = new BufferedReader(new InputStreamReader(p.getErrorStream()));
  177. //println("Error:");
  178. //while ( (returnedValues = stdErr.readLine ()) != null) {
  179. //println(returnedValues);
  180. //}
  181. return(false);
  182. }
  183. }
  184. catch (Exception e) {
  185. //println("Error running command");
  186. //println(e);
  187. return(false);
  188. }
  189. }*/
  190. int runCommand(String[] command) {
  191. String returnedValues;
  192. try {
  193. println(command);
  194. Process p = new ProcessBuilder(command).start();
  195. int ii = p.waitFor();
  196. BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
  197. BufferedReader stdErr = new BufferedReader(new InputStreamReader(p.getErrorStream()));
  198. while ( (returnedValues = stdInput.readLine ()) != null) {
  199. println(returnedValues);
  200. }
  201. while ( (returnedValues = stdErr.readLine ()) != null) {
  202. println(returnedValues);
  203. }
  204. println(ii);
  205. return(ii);
  206. }
  207. catch (Exception e) {
  208. println("Error running command");
  209. println(command);
  210. println(e);
  211. return(3); //error signal
  212. }
  213. }