iomikron

Rotating rectangles - hypnosis 001

Oct 19th, 2012
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. // iomikron.tumblr.com
  2.  
  3. //this is for gif creation//import gifAnimation.*;
  4.  
  5. //this is for gif creation//GifMaker gifExport = new GifMaker(this, "rotatedSquare05.gif");
  6.  
  7. int numOfRectangles = 400;
  8. Rectangle [] rectArray = new Rectangle[numOfRectangles];
  9.  
  10. void setup()
  11. {
  12. size(600, 150);
  13. //this is for gif creation// gifExport.setRepeat(0); //make it an 'endless' animation
  14. for(int i = 0; i <= numOfRectangles-1; i++)
  15. {
  16. rectArray[i] =
  17. new Rectangle(
  18. random(10, width - 10), //coordinate X
  19. random(10,height - 10), //coordinate Y
  20. 133, //color
  21. 20., //width
  22. 20., //height
  23. (PI/(i+1)), //angle (initial)
  24. random(3.1,4.), //angular Velocity (initial)
  25. random(0.05,0.25),//rotate speed (initial)
  26. 0.5,//initial value for time
  27. 0.000225//constant timeStep
  28. );
  29. }
  30. }
  31.  
  32. void draw()
  33. {
  34. background(0);
  35. for(int i = 0; i <= numOfRectangles-1; i++)
  36. {
  37. rectArray[i].move();
  38. }
  39.  
  40. //this is for gif creation// if(keyPressed == true)
  41. //this is for gif creation// {
  42. //this is for gif creation// gifExport.finish();
  43. //this is for gif creation// }
  44. //this is for gif creation// else
  45. //this is for gif creation// {
  46. //this is for gif creation// gifExport.addFrame();
  47. //this is for gif creation// }
  48. }
  49. ///////////////////////////////////////////////////////
  50. // Rectangle CLASS DEFINITION
  51. ///////////////////////////////////////////////////////
  52. class Rectangle
  53. {
  54. float coordX;//horizontal coordinate for the center
  55. float coordY;//vertical coordinate for the center
  56. float rectColor;//color filling
  57. // float rectAlpha; Uncomment for opacity
  58. float rectWidth;//parameter for the width
  59. float widthConst;
  60. float rectHeight;//parameter for the height
  61. float angle;
  62. float angularVelocity;
  63. float rotationSpeed;
  64. float time;
  65. float timeStep;
  66. //-----------------------------------------------------
  67. // Constructor
  68. //-----------------------------------------------------
  69. Rectangle(float X, float Y,
  70. float C,
  71. float W, float H,
  72. float a, float angV, float rotS,
  73. float T, float TS)
  74. {
  75. coordX = X;
  76. coordY = Y;
  77. rectColor = C;
  78. rectWidth = W;
  79. widthConst = W;
  80. rectHeight = H;
  81. angle = a;
  82. angularVelocity = angV;
  83. rotationSpeed = rotS;
  84. time = T;
  85. timeStep = TS;
  86. }
  87. ///////////////////////////////////////////////////////
  88. // FUNCTIONS FOR THE CLASS
  89. ///////////////////////////////////////////////////////
  90.  
  91. // color and transparency \\
  92. void display()
  93. {
  94. rectMode(CENTER);
  95. //define color and opacity
  96. noStroke();
  97. fill(changeColor(),
  98. 200*(cos(4*height*time))*(cos(4*height*time)));
  99. //create the rectangle
  100. rect(0, 0, widthConst*changeWidth(), rectHeight);
  101. }
  102.  
  103. // movement \\
  104. void move()
  105. {
  106. pushMatrix();
  107. translate(coordX, coordY);
  108. rotate(radians(angle));
  109. scale((cos(4*height*time))*(cos(4*height*time)) + 0.5);
  110. display();
  111.  
  112. popMatrix();
  113.  
  114. changeAngle();
  115.  
  116. changeWidth();
  117.  
  118. time = time + timeStep;
  119. }
  120.  
  121. float changeAngle()
  122. {
  123. angle = angle + angularVelocity;
  124. return(angle);
  125. }
  126.  
  127. float changeWidth()
  128. {
  129. float w;
  130. rectWidth = rectWidth + rotationSpeed;
  131. w = cos(rectWidth);
  132. return(w);
  133. }
  134.  
  135. float changeColor()
  136. {
  137. float c;
  138. c = rectColor*cos(rectWidth)*cos(rectWidth) + 120;
  139. return(c);
  140. }
  141.  
  142. }
Advertisement
Add Comment
Please, Sign In to add comment