Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.75 KB | None | 0 0
  1. // CFI - Drawing Machines - Janny, Ji
  2.  
  3. // Texture Text Machine
  4.  
  5. ArrayList<JannysMinionClass> JannysMinionClassList;
  6. //int totalNumberOfJannysMinionClasss = 100;
  7.  
  8. PGraphics jannysForegroundPGraphic;
  9. PGraphics jannysBackgroundPGraphic;
  10. PImage jannysForegroundPImage;
  11. PImage jannysBackgroundPImage;
  12.  
  13. int myBackgroundTextureID = 3; // set this to 1-5
  14. Boolean showBackground = false;
  15.  
  16. //int myOverallAnimationSpeed = 100; // set this between 1 to 100 ish
  17.  
  18. color jannysCheckPixelColor;
  19. color jannysCheckColor = color(0);
  20. float jannysGridSpacing;
  21. float distanceToMouse;
  22.  
  23. // Minions
  24. int minionSize = 5;
  25. float minionEasingSlow = .05;
  26. float minionEasingFast = .2;
  27. float minionSizeMin = 5; // CHANGE THIS to adjust default minimum module scale
  28. float minionSizeMax = 100; // CHANGE THIS to adjust default maximum module scale
  29. PVector minionVelocity = new PVector(0, 0);
  30. int jannysGridOffsetY = 0;
  31. int jjGridOffsetX = 0;
  32. int jjColumns = 47; //47
  33.  
  34. void setup() {
  35. size(960, 540);
  36. colorMode(HSB, 255, 255, 255, 100);
  37. jannysGridSpacing = width/jjColumns;
  38.  
  39. minionVelocity = new PVector(1, 1);
  40. //frameRate(myOverallAnimationSpeed); // change the frame rate to change the speed
  41.  
  42. // this graphic holds the background image
  43. switch(myBackgroundTextureID) {
  44. case 2:
  45. jannysBackgroundPImage = loadImage("texture2.png");
  46. break;
  47. case 3:
  48. jannysBackgroundPImage = loadImage("texture4.png");
  49. break;
  50. default:
  51. jannysBackgroundPImage = loadImage("texture1.png");
  52. break;
  53. }
  54. jannysBackgroundPGraphic = createGraphics(width, height);
  55. jannysBackgroundPGraphic.beginDraw();
  56. jannysBackgroundPGraphic.image(jannysBackgroundPImage, 0, 0);
  57. jannysBackgroundPGraphic.endDraw();
  58.  
  59. // this holds the vector graphic of the minions
  60. jannysForegroundPGraphic = createGraphics(width, height);
  61. jannysForegroundPGraphic.noStroke();
  62.  
  63. // this holds the pixel image of the minions
  64. jannysForegroundPImage = loadImage("texture4.png");
  65.  
  66. // Create an empty ArrayList (will store JannysMinionClass objects)
  67. JannysMinionClassList = new ArrayList<JannysMinionClass>();
  68.  
  69. // add the modules using a loop
  70.  
  71. for (float y = jannysGridOffsetY; y < height; y+= jannysGridSpacing) {
  72. for (float x = jjGridOffsetX; x < width; x+= jannysGridSpacing) {
  73.  
  74. jannysCheckPixelColor = jannysBackgroundPGraphic.get(int(x), int(y));
  75.  
  76. if (jannysCheckPixelColor != jannysCheckColor) {
  77. JannysMinionClassList.add(new JannysMinionClass(x, y));
  78. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  79. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  80. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  81. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  82. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  83. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  84. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  85. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  86. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  87. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  88. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  89. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  90. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  91. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  92. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  93. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  94. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  95. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  96. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  97. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  98. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  99. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  100. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  101. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  102. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  103. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  104. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  105. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  106. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  107. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  108. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  109. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  110. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  111. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  112. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  113. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  114. JannysMinionClassList.add(new JannysMinionClass(x, y));//janny trying to make more sand
  115. }
  116. }
  117. }
  118. }
  119.  
  120.  
  121. void draw() {
  122. background(0);
  123. if (showBackground) image(jannysBackgroundPGraphic, 0, 0);
  124. for (JannysMinionClass jannysMod : JannysMinionClassList) {
  125. jannysMod.myUpdate();
  126. jannysMod.myDisplay();
  127. }
  128. jannysForegroundPGraphic.clear();
  129. //jannysForegroundPGraphic.filter(BLUR, 3);
  130. image(jannysForegroundPGraphic, 0, 0);
  131. }
  132.  
  133. // --------------------------------------------------------
  134. // --------------------------------------------------------
  135. // --------------------------------------------------------
  136. // --------------------------------------------------------
  137. class JannysMinionClass {
  138. float myAge;
  139. PVector myOrigin, myPosition, myVelocity, myTarget, myDistance; // (x,y) myOrigin.x /myPosition.y
  140. float mySize = minionSize;
  141. int myHue = 255;
  142. int mySaturation = 0;
  143. float myBrightness = 255;
  144. color checkColor;
  145.  
  146. // Contructor (similar to SETUP. Only runs once when the instance is "born")
  147. JannysMinionClass(float xTemp, float yTemp) {
  148. myAge = 0;
  149. myOrigin = new PVector(xTemp, yTemp);
  150. myPosition = new PVector(xTemp, yTemp);
  151. myTarget = new PVector(xTemp, yTemp);
  152. myDistance = new PVector(0, 0);
  153. //myVelocity = new PVector(0, 0); // no velocity
  154. myVelocity = new PVector(random(5), -random(5));
  155. mySize = minionSize;
  156. myHue = 255;
  157. mySaturation = 0;
  158. myBrightness = 255;
  159. }
  160.  
  161. // Custom method for updating the variables
  162. void myUpdate() {
  163. //myRandomGray();
  164. // myVelocity();
  165. //myGrow();
  166. //if (myNearMouse()) myRandomGray();
  167. if (myNearMouse()) myVelocity(); //janny testing sandy
  168. //if (myNearMouse()) myGrow(); else myShrink();
  169. //if (myNearMouse()) myTarget.copy(); else myShrink(); //janny testing making copy
  170. if (myNearMouse()) mySize =3; // janny testing fatty
  171. //if (myNearMouse()) mySize =random(1,70); else myShrink(); // janny testing
  172. //jmgSaveFrames();
  173. myAge++;
  174. checkColor = jannysBackgroundPGraphic.get(int(myPosition.x), int(myPosition.y));
  175. }
  176.  
  177. // Custom method for drawing the object
  178. void myDisplay() {
  179. jannysForegroundPGraphic.beginDraw();
  180. jannysForegroundPGraphic.noStroke();
  181. jannysForegroundPGraphic.fill(myBrightness);
  182. jannysForegroundPGraphic.ellipse(myPosition.x, myPosition.y, mySize, mySize);
  183. jannysForegroundPGraphic.endDraw();
  184. }
  185.  
  186. void myRandomGray() {
  187. myBrightness = int(random(255));
  188. }
  189.  
  190. void myVelocity() {
  191. myPosition.x += myVelocity.x;
  192. myPosition.y += myVelocity.y;
  193. }
  194.  
  195. Boolean myNearMouse() {
  196. distanceToMouse = dist(myPosition.x, myPosition.y, mouseX, mouseY);
  197. if (distanceToMouse < 100) {
  198. return true;
  199. } else {
  200. return false;
  201. }
  202. }
  203.  
  204. ///////////////
  205.  
  206. void myGrow() {
  207. //if (mySize>minionSizeMax) mySize = minionSizeMax;
  208. if (mySize>20) mySize = 20;//janny testing silky
  209. else mySize++;
  210. }
  211.  
  212. void myShrink() {
  213. //if (mySize<minionSizeMin) mySize = minionSizeMin;
  214. if (mySize<5) mySize = 5;//janny testing silky
  215. else mySize--;
  216. }
  217.  
  218. // This function moves the Module away from the mouse
  219. // if it is within a certain distance
  220. void myAvoidMouse() {
  221. myTarget.x = mouseX;
  222. myDistance.x = myTarget.x - myPosition.x;
  223. myPosition.x -= myDistance.x * minionEasingSlow;
  224.  
  225. myTarget.y = mouseY;
  226. myDistance.x = myTarget.y - myPosition.y;
  227. myPosition.y -= myDistance.x * minionEasingSlow;
  228. }
  229.  
  230. // This function moves the Module back towards it's point of orgin
  231. void myGoHome() {
  232. myTarget.x = myOrigin.x;
  233. myDistance.x = myTarget.x - myPosition.x;
  234. myPosition.x += myDistance.x * minionEasingFast;
  235.  
  236. myTarget.y = myOrigin.y;
  237. myDistance.x = myTarget.y - myPosition.y;
  238. myPosition.y += myDistance.x * minionEasingFast;
  239. }
  240. }
  241.  
  242. //// This function saves a png of the current frame. Calling this
  243. //// function on everyframe will give you all the frames you need
  244. //// to make a video using Processing's "Movie Maker"
  245. //void jjSaveFrames(){
  246. // saveFrame("frames/####.png");
  247. //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement