compositor for 2d shader
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.

mangler2_0001.pde 4.0KB

11 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import drop.*;
  2. import test.*;
  3. import java.util.*;
  4. import processing.net.*;
  5. import java.awt.event.KeyEvent;
  6. import java.awt.event.KeyListener;
  7. import processing.video.*;
  8. import com.hamoid.*;
  9. VideoExport videoExport;
  10. boolean greenBackground = false; //else: black
  11. boolean roundMask = false; // show a circle
  12. boolean drawGUI = true; //draws fx-informations
  13. int mode = 1; //0: webcam, 1: image
  14. boolean harvester = true;
  15. int maxFx = 5; //possible amount of effect layers
  16. int frameRate = 30;
  17. int fpm = frameRate * 60;
  18. int bpm = 128;
  19. SDrop drop;
  20. PImage source;
  21. PGraphics renderer;
  22. PImage viewport;
  23. SourceManager sourceManager;
  24. PImage roundMaskImage;
  25. PGraphics roundMaskGraphics;
  26. String frameName; //to save frame as image
  27. float uptime; //logs how many frames this software has rendered before (inaccurate, it's actually way, way more)
  28. boolean recording; //save every frame?
  29. int renderSize = 500; //px
  30. String[] saveData;
  31. int w, h;
  32. void setup() {
  33. size(640, 800);
  34. w = width;
  35. h = height;
  36. surface.setResizable(true);
  37. frameRate(frameRate);
  38. noSmooth(); //saves resources but makes sum look shiddy
  39. drop = new SDrop(this);
  40. saveData = loadStrings(dataPath("saves.sav"));
  41. println("Loading Savefile...");
  42. for (int i = 0; i < saveData.length; i ++) {
  43. float[] temp;
  44. if (saveData[i].contains("uptime")) {
  45. temp = float(split(saveData[i], " = "));
  46. println("Uptime: " + temp[1]);
  47. uptime = temp[1];
  48. }
  49. }
  50. fallbackImage = loadImage(dataPath("0.png"));
  51. /*
  52. String[] cameras = Capture.list();
  53. if (cameras == null || cameras.length == 0) {
  54. println(cameras == null ? "Failed to retrieve the list of available cameras." : "There are no cameras available for capture.");
  55. if (mode == 0) {
  56. println("Switching to image mode");
  57. mode = 1;
  58. }
  59. } else {
  60. println("Available cameras:");
  61. printArray(cameras);
  62. cam = new Capture(this, cameras[0]);
  63. cam.start();
  64. }
  65. */
  66. composiorServer = new Server(this, port); // 10002
  67. renderer = createGraphics(width, height);
  68. viewport = createImage(renderer.width, renderer.height, ARGB);
  69. roundMaskGraphics = createGraphics(renderer.width, renderer.height);
  70. sourceManager = new SourceManager();
  71. masksRender = new PImage[masksRenderAmount];
  72. sobel = new SobelEdgeDetection();
  73. sourceManager.importURI("/home/giers/.local/bin/fast-style-transfer/data/train2014");
  74. //sourceManager.importURI(dataPath(""));
  75. }
  76. void draw() {
  77. updateServer();
  78. sourceManager.update(); //will write some image to the renderer
  79. sourceManager.setSource();
  80. fxManager.run(true, true); //boolean animate (iterative calcs), boolean apply (draw)
  81. render();
  82. background(greenBackground ? color(0, 255, 0) : color(0));
  83. imageMode(CENTER);
  84. viewport = renderer.get();
  85. if (renderer.width < renderer.height) {
  86. viewport.resize(0, height);
  87. if (viewport.width > width) viewport.resize(width, 0);
  88. } else {
  89. viewport.resize(width, 0);
  90. if (viewport.height > height) viewport.resize(0, height);
  91. }
  92. if (roundMask) {
  93. roundMaskGraphics.setSize(viewport.width, viewport.height);
  94. roundMaskGraphics.beginDraw();
  95. roundMaskGraphics.noStroke();
  96. roundMaskGraphics.background(0);
  97. roundMaskGraphics.fill(255);
  98. roundMaskGraphics.ellipse(viewport.width/2, viewport.height/2, min(viewport.width, viewport.height), min(viewport.width, viewport.height));
  99. roundMaskGraphics.endDraw();
  100. roundMaskImage = roundMaskGraphics.get();
  101. viewport.mask(roundMaskImage);
  102. }
  103. //sourceManager.setSource();
  104. //viewport = getEdges(viewport);
  105. //viewport = cannyEdge(viewport);
  106. image(viewport, width/2, height/2);
  107. if (videoRecord) {
  108. videoExport.saveFrame();
  109. fill(#ff0000);
  110. ellipse(width-100,height-100,30,30);
  111. }
  112. if (drawGUI) drawGUI(guiOffsetTop);
  113. if (recording) {
  114. snapshot();
  115. if (airisRendering) {
  116. airisRendering = false;
  117. recording = previousRecordState;
  118. renderSize = previousRenderSize;
  119. println("i rendered something big, oops");
  120. }
  121. }
  122. }