Advertisement
Guest User

Untitled

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