Advertisement
Guest User

Untitled

a guest
Aug 28th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. void setup() {
  2. setup_();
  3. result = new int[width*height][3];
  4. result_ = new int[width*height][3];
  5. }
  6.  
  7. int[][] result, result_;
  8. float time;
  9.  
  10. void draw_() {
  11. if (aberrationAmount == 0.0) {
  12. draw__();
  13. return;
  14. }
  15.  
  16. for (int i=0; i<width*height; i++)
  17. for (int a=0; a<3; a++)
  18. result_[i][a] = 0;
  19.  
  20. for (int a=0; a<3; a++) {
  21. pushMatrix();
  22. translate(width/2, height/2);
  23. scale(1+0.008*a*aberrationAmount);
  24. translate(-width/2, -height/2);
  25. draw__();
  26. popMatrix();
  27. loadPixels();
  28. for (int i=0; i<pixels.length; i++) {
  29. result_[i][a] = pixels[i] >> (8*(2-a)) & 0xff;
  30. }
  31. }
  32.  
  33. loadPixels();
  34. for (int i=0; i<pixels.length; i++)
  35. pixels[i] = 0xff << 24 | result_[i][0] << 16 |
  36. result_[i][1] << 8 | result_[i][2];
  37. updatePixels();
  38. }
  39.  
  40. void draw() {
  41. if (shutterAngle == 0.0) {
  42. time = map(frameCount-1, 0, numFrames, 0, 1) % 1;
  43. draw_();
  44. return;
  45. }
  46.  
  47. for (int i=0; i<width*height; i++)
  48. for (int a=0; a<3; a++)
  49. result[i][a] = 0;
  50.  
  51. for (int sa=0; sa<samplesPerFrame; sa++) {
  52. time = map(frameCount-1 + sa*shutterAngle/samplesPerFrame, 0, numFrames, 0, 1);
  53. draw_();
  54. loadPixels();
  55. for (int i=0; i<pixels.length; i++) {
  56. result[i][0] += pixels[i] >> 16 & 0xff;
  57. result[i][1] += pixels[i] >> 8 & 0xff;
  58. result[i][2] += pixels[i] & 0xff;
  59. }
  60. }
  61.  
  62. loadPixels();
  63. for (int i=0; i<pixels.length; i++)
  64. pixels[i] = 0xff << 24 | (result[i][0]/samplesPerFrame) << 16 |
  65. (result[i][1]/samplesPerFrame) << 8 | (result[i][2]/samplesPerFrame);
  66. updatePixels();
  67.  
  68. saveFrame("f###.gif");
  69. if (frameCount==numFrames)
  70. exit();
  71. }
  72.  
  73. ////////////////////////////////////////////////////
  74.  
  75. float aberrationAmount = .4;
  76.  
  77. int samplesPerFrame = 4;
  78. int numFrames = 132;
  79. float shutterAngle = .75;
  80.  
  81. void setup_() {
  82. size(500, 500, P2D);
  83. smooth(8);
  84. noStroke();
  85. }
  86.  
  87. float l = 30, sp = 2*l, t, tt;
  88. float x, y;
  89. float c1 = 26, c2 = 240;
  90. int N = 7;
  91.  
  92. float ease(float p){
  93. float g = 3*p*p - 2*p*p*p;
  94. g = 3*g*g - 2*g*g*g;
  95. return 3*g*g - 2*g*g*g;
  96. }
  97.  
  98. void draw__() {
  99. t = time;
  100. background(62);
  101.  
  102. pushMatrix();
  103. translate(width/2, height/2);
  104. rotate(QUARTER_PI);
  105.  
  106. if (t <= .275) {
  107. tt = map(t,0,.275,0,1);
  108. tt = ease(tt);
  109. for (int i=-N; i<=N; i++) {
  110. for (int j=-N; j<=N; j++) {
  111. for (int a=0; a<4; a++) {
  112. x = 0+i*sp;
  113. y = 0+j*sp;
  114.  
  115. if (a<2)
  116. x += .5*tt*sp;
  117. else
  118. x -= .5*tt*sp;
  119. pushMatrix();
  120. fill((i+j)%2 == 0 ? c1 : c2);
  121. translate(x, y);
  122. rotate(HALF_PI*a);
  123. rect(0, 0, l/2, l/2);
  124. popMatrix();
  125. }
  126. }
  127. }
  128. }
  129. else if (t <= 0.55) {
  130. tt = map(t,.275,.55,0,1);
  131. tt = ease(tt);
  132. for (int i=-N; i<=N; i++) {
  133. for (int j=-N; j<=N; j++) {
  134. for (int a=0; a<4; a++) {
  135. x = 0+(i+.5)*sp;
  136. y = 0+j*sp;
  137.  
  138. if (a==0||a==3)
  139. y += .5*tt*sp;
  140. else
  141. y -= .5*tt*sp;
  142. pushMatrix();
  143. fill((i+j+a/2)%2 == 0 ? c1 : c2);
  144. translate(x, y);
  145. rotate(HALF_PI*a);
  146. rect(0, 0, l/2, l/2);
  147. popMatrix();
  148. }
  149. }
  150. }
  151. }
  152.  
  153. else if (t <= 0.775) {
  154. tt = map(t,0.55,0.775,0,1);
  155. tt = ease(tt);
  156. for (int i=-N; i<=N; i++) {
  157. for (int j=-N; j<=N; j++) {
  158. for (int a=0; a<4; a++) {
  159. x = 0+(i+.5)*sp;
  160. y = 0+(j+.5)*sp;
  161.  
  162. if (a==0||a==3)
  163. x += .25*tt*sp;
  164. else
  165. x -= .25*tt*sp;
  166. pushMatrix();
  167. fill((i+j+a)%2 == 0 ? c1 : c2);
  168. translate(x, y);
  169. rotate(HALF_PI*a);
  170. rect(0, 0, l/2, l/2);
  171. popMatrix();
  172. }
  173. }
  174. }
  175. }
  176.  
  177. else {
  178. tt = map(t,0.775,1,0,1);
  179. tt = ease(tt);
  180. for (int i=-N; i<=N; i++) {
  181. for (int j=-N; j<=N; j++) {
  182. for (int a=0; a<4; a++) {
  183. x = 0+i*sp;
  184. y = 0+(j+.5)*sp;
  185.  
  186. if (a<2)
  187. y += .25*tt*sp;
  188. else
  189. y -= .25*tt*sp;
  190. pushMatrix();
  191. fill((i+j+a/2+1)%2 == 0 ? c1 : c2);
  192. translate(x, y);
  193. rotate(HALF_PI*a);
  194. rect(0, 0, l/2, l/2);
  195. popMatrix();
  196. }
  197. }
  198. }
  199. }
  200. popMatrix();
  201. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement