Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 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. void draw() {
  28.  
  29. if (!recording) {
  30. t = mouseX*1.0/width;
  31. c = mouseY*1.0/height;
  32. if (mousePressed)
  33. println(c);
  34. draw_();
  35. } else {
  36. for (int i=0; i<width*height; i++)
  37. for (int a=0; a<3; a++)
  38. result[i][a] = 0;
  39.  
  40. c = 0;
  41. for (int sa=0; sa<samplesPerFrame; sa++) {
  42. t = map(frameCount-1 + sa*shutterAngle/samplesPerFrame, 0, numFrames, 0, 1);
  43. draw_();
  44. loadPixels();
  45. for (int i=0; i<pixels.length; i++) {
  46. result[i][0] += pixels[i] >> 16 & 0xff;
  47. result[i][1] += pixels[i] >> 8 & 0xff;
  48. result[i][2] += pixels[i] & 0xff;
  49. }
  50. }
  51.  
  52. loadPixels();
  53. for (int i=0; i<pixels.length; i++)
  54. pixels[i] = 0xff << 24 |
  55. int(result[i][0]*1.0/samplesPerFrame) << 16 |
  56. int(result[i][1]*1.0/samplesPerFrame) << 8 |
  57. int(result[i][2]*1.0/samplesPerFrame);
  58. updatePixels();
  59.  
  60. saveFrame("f###.gif");
  61. if (frameCount==numFrames)
  62. exit();
  63. }
  64. }
  65.  
  66. //////////////////////////////////////////////////////////////////////////////
  67.  
  68. int samplesPerFrame = 4;
  69. int numFrames = 240;
  70. float shutterAngle = .6;
  71.  
  72. boolean recording = false;
  73.  
  74. void setup() {
  75. size(800, 720);
  76. result = new int[width*height][3];
  77. rectMode(CENTER);
  78. fill(32);
  79. noStroke();
  80. }
  81.  
  82. float x, y, z, tt;
  83. int N = 12;
  84. float l = 42;
  85.  
  86. void swimmer(float q) {
  87. push();
  88. y = map(sin(TWO_PI*q), 1, -1, 0, 1);
  89. y = lerp(-l*2*mn, l*2*mn, ease(y,4.5));
  90. translate(0, y);
  91. tri(ease(map(cos(TWO_PI*q), 1, -1, 0, 1), 6));
  92. pop();
  93. }
  94.  
  95. void tri(float q) {
  96. push();
  97. translate(0,lerp(-l*.25,l*.25,q));
  98.  
  99. push();
  100. rotate(PI*5/6*q);
  101. halfTri(q);
  102. pop();
  103.  
  104. push();
  105. scale(-1, 1);
  106. rotate(PI*5/6*q);
  107. halfTri(q);
  108. pop();
  109.  
  110. pop();
  111. }
  112.  
  113. void halfTri(float q) {
  114. push();
  115. scale(map(cos(TWO_PI*q),1,-1,1,0.85));
  116. beginShape();
  117. vertex(0, 0);
  118. vertex(0, lerp(l*mn, l, q));
  119. vertex(lerp(-l/2, -l*mn/2, q), lerp(l*mn, l*.75, q));
  120. endShape(CLOSE);
  121. pop();
  122. }
  123.  
  124. float sp = 2*l;
  125. int in;
  126.  
  127. void draw_() {
  128. background(250);
  129. push();
  130. translate(width/2, height/2);
  131. for (int i=-N; i<=N; i++) {
  132. for (int j=-N; j<=N; j++) {
  133. x = i*sp;
  134. y = j*mn*sp;
  135. if (j%2 != 0)
  136. x += .5*sp;
  137. tt = (t + 100 - 0.0003*dist(x,y,0,0))%1;
  138. push();
  139. translate(x, y);
  140. fill(#86C986);
  141. in = (2*i+100+3*j+(j+100)%2); // dunno lol
  142. if(in%3 == 0)
  143. fill(#31A7C4);
  144. if(in%3 == 1)
  145. fill(#561D72);
  146. swimmer(tt);
  147. pop();
  148. }
  149. }
  150. pop();
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement