Guest User

Untitled

a guest
May 27th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. int[][] result;
  2. float t, c;
  3.  
  4. float ease(float p) {
  5. return 3*p*p - 2*p*p*p;
  6. }
  7.  
  8. float ease(float p, float g) {
  9. if (p < 0.5)
  10. return 0.5 * pow(2*p, g);
  11. else
  12. return 1 - 0.5 * pow(2*(1 - p), g);
  13. }
  14.  
  15. float mn = .5*sqrt(3), ia = atan(sqrt(.5));
  16.  
  17. void push() {
  18. pushMatrix();
  19. pushStyle();
  20. }
  21.  
  22. void pop() {
  23. popStyle();
  24. popMatrix();
  25. }
  26.  
  27. float c01(float g) {
  28. return constrain(g, 0, 1);
  29. }
  30.  
  31. void draw() {
  32.  
  33. if (!recording) {
  34. t = mouseX*1.0/width;
  35. c = mouseY*1.0/height;
  36. if (mousePressed)
  37. println(c);
  38. draw_();
  39. } else {
  40. for (int i=0; i<width*height; i++)
  41. for (int a=0; a<3; a++)
  42. result[i][a] = 0;
  43.  
  44. c = 0;
  45. for (int sa=0; sa<samplesPerFrame; sa++) {
  46. t = map(frameCount-1 + sa*shutterAngle/samplesPerFrame, 0, numFrames, 0, 1);
  47. draw_();
  48. loadPixels();
  49. for (int i=0; i<pixels.length; i++) {
  50. result[i][0] += pixels[i] >> 16 & 0xff;
  51. result[i][1] += pixels[i] >> 8 & 0xff;
  52. result[i][2] += pixels[i] & 0xff;
  53. }
  54. }
  55.  
  56. loadPixels();
  57. for (int i=0; i<pixels.length; i++)
  58. pixels[i] = 0xff << 24 |
  59. int(result[i][0]*1.0/samplesPerFrame) << 16 |
  60. int(result[i][1]*1.0/samplesPerFrame) << 8 |
  61. int(result[i][2]*1.0/samplesPerFrame);
  62. updatePixels();
  63.  
  64. saveFrame("f###.gif");
  65. if (frameCount==numFrames)
  66. exit();
  67. }
  68. }
  69.  
  70. //////////////////////////////////////////////////////////////////////////////
  71.  
  72. int samplesPerFrame = 8;
  73. int numFrames = 360;
  74. float shutterAngle = 1;
  75.  
  76. boolean recording = false;
  77.  
  78. void setup() {
  79. size(720, 720, P3D);
  80. pixelDensity(recording ? 1 : 2);
  81. smooth(8);
  82. result = new int[width*height][3];
  83. rectMode(CENTER);
  84. fill(32);
  85. noStroke();
  86. ortho();
  87. }
  88.  
  89. float x, y, z, tt, t1;
  90. int N = 12;
  91. color c1 = #282828, c2 = #006f3c, c3 = #e177a8;
  92. float l, r;
  93. float eas = 4;
  94.  
  95. void cube() {
  96. for (int i=0; i<4; i++) {
  97. push();
  98. fill(i%2 == 0?c1:c2);
  99. rotateY(HALF_PI*i);
  100. translate(0, 0, l/2);
  101. rect(0, 0, l, l);
  102. pop();
  103. }
  104.  
  105. for (int i=0; i<2; i++) {
  106. push();
  107. fill(c3);
  108. rotateX(HALF_PI+PI*i);
  109. translate(0, 0, l/2);
  110. rect(0, 0, l, l);
  111. pop();
  112. }
  113. }
  114.  
  115. void shard() {
  116. beginShape();
  117. vertex(0, -r);
  118. vertex(0, -2*r);
  119. vertex(2*r*mn, -r);
  120. vertex(r*mn, -r/2);
  121. endShape();
  122. }
  123.  
  124. void draw_() {
  125. t1 = c01(1.1*t);
  126. tt = c01(1.25*t-0.25);
  127. l = 180*pow(2,-t);
  128. r = l*.815; // trial & error
  129.  
  130. background(250);
  131. push();
  132. translate(width/2, height/2);
  133. push();
  134. rotateX(-ia);
  135. rotateY(QUARTER_PI);
  136.  
  137. rotateX(-HALF_PI*ease(c01(4*t1-3),eas));
  138. rotate(-HALF_PI*ease(c01(4*t1-2),eas));
  139. rotateX(-HALF_PI*ease(c01(4*t1-1),eas));
  140. rotateY(-HALF_PI*ease(c01(4*t1),eas));
  141.  
  142. cube();
  143. pop();
  144. for (int i=0; i<6; i++) {
  145. fill(c1);
  146. if(i>1)
  147. fill(c2);
  148. if(i>3)
  149. fill(c3);
  150. push();
  151. rotate(TWO_PI*(i+1)/6);
  152. translate(0,-600 + 600*(1-sq(1-tt)));
  153. shard();
  154. pop();
  155. }
  156. pop();
  157. }
Add Comment
Please, Sign In to add comment