Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. // by dave @beesandbombs
  2.  
  3. int[][] result;
  4. float t, c;
  5.  
  6. float ease(float p) {
  7. return 3*p*p - 2*p*p*p;
  8. }
  9.  
  10. float ease(float p, float g) {
  11. if (p < 0.5)
  12. return 0.5 * pow(2*p, g);
  13. else
  14. return 1 - 0.5 * pow(2*(1 - p), g);
  15. }
  16.  
  17. float mn = .5*sqrt(3), ia = atan(sqrt(.5));
  18.  
  19. void push() {
  20. pushMatrix();
  21. pushStyle();
  22. }
  23.  
  24. void pop() {
  25. popStyle();
  26. popMatrix();
  27. }
  28.  
  29. void draw() {
  30.  
  31. if (!recording) {
  32. t = mouseX*1.0/width;
  33. c = mouseY*1.0/height;
  34. if (mousePressed)
  35. println(c);
  36. draw_();
  37. } else {
  38. for (int i=0; i<width*height; i++)
  39. for (int a=0; a<3; a++)
  40. result[i][a] = 0;
  41.  
  42. c = 0;
  43. for (int sa=0; sa<samplesPerFrame; sa++) {
  44. t = map(frameCount-1 + sa*shutterAngle/samplesPerFrame, 0, numFrames, 0, 1);
  45. draw_();
  46. loadPixels();
  47. for (int i=0; i<pixels.length; i++) {
  48. result[i][0] += pixels[i] >> 16 & 0xff;
  49. result[i][1] += pixels[i] >> 8 & 0xff;
  50. result[i][2] += pixels[i] & 0xff;
  51. }
  52. }
  53.  
  54. loadPixels();
  55. for (int i=0; i<pixels.length; i++)
  56. pixels[i] = 0xff << 24 |
  57. int(result[i][0]*1.0/samplesPerFrame) << 16 |
  58. int(result[i][1]*1.0/samplesPerFrame) << 8 |
  59. int(result[i][2]*1.0/samplesPerFrame);
  60. updatePixels();
  61.  
  62. saveFrame("p####.gif");
  63. if (frameCount==numFrames)
  64. exit();
  65. }
  66. }
  67.  
  68. //////////////////////////////////////////////////////////////////////////////
  69.  
  70. int samplesPerFrame = 4;
  71. int numFrames = 1080;
  72. float shutterAngle = .5;
  73.  
  74. boolean recording = false;
  75.  
  76. void setup() {
  77. size(750, 750, P2D);
  78. smooth(8);
  79. strokeWeight(1.5);
  80. strokeCap(ROUND);
  81. result = new int[width*height][3];
  82. }
  83.  
  84. float x, y, z, tt;
  85. float l = 75;
  86.  
  87. void poly(int N) {
  88. for (int i=0; i<N; i++) {
  89. push();
  90. rotate(TWO_PI*i/N);
  91. line(-l/2, l/(2*tan(PI/N)), l/2, l/(2*tan(PI/N)));
  92. pop();
  93. }
  94. }
  95.  
  96. float qq, rot;
  97.  
  98. void walker(int N, float q) {
  99. qq = (N*q)%1;
  100. rot = TWO_PI*int(N*q)/N;
  101. push();
  102. rotate(rot);
  103. translate(-l/2, l/(2*tan(PI/N)));
  104. rotate((PI*2/3 + TWO_PI/N)*ease(qq));
  105. triangle(0, 0, l, 0, l/2, l*mn);
  106. pop();
  107. }
  108.  
  109. void draw_() {
  110. background(255);
  111. push();
  112. translate(width/2, height/2);
  113. rotate(PI);
  114.  
  115. stroke(0);
  116. noFill();
  117. blendMode(NORMAL);
  118. for (int i=3; i<12; i++) {
  119. l = 12 + 10*i;
  120. poly(i);
  121. }
  122.  
  123. fill(255);
  124. noStroke();
  125. blendMode(EXCLUSION);
  126. for (int i=3; i<12; i++) {
  127. l = 12 + 10*i;
  128. walker(i, (13-i)*t);
  129. }
  130.  
  131. pop();
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement