Guest User

Untitled

a guest
May 22nd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 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 = 4;
  73. int numFrames = 180;
  74. float shutterAngle = .6;
  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. blendMode(MULTIPLY);
  87. }
  88.  
  89. float x, y, z, tt;
  90. int N = 8;
  91. float r = 250;
  92. int n = 120, m = 120;
  93. float qq;
  94. float wh = 16;
  95. float sw = .2;
  96.  
  97. void circ(float q) {
  98. for (int i=0; i<N; i++)
  99. slice(map(i+.5-sw, 0, N, -r, r), map(i+.5+sw, 0, N, -r, r), q);
  100. }
  101.  
  102. void waveVertex(float x_, float y_, float q) {
  103. vertex(x_, y_+wh*sin(.02*x_ + TWO_PI*t + q));
  104. }
  105.  
  106. void slice(float y1, float y2, float q) {
  107. beginShape();
  108. for (int i=0; i<n; i++) {
  109. qq = i/float(n);
  110. y = lerp(y1, y2, qq);
  111. x = -sqrt(r*r-y*y);
  112. waveVertex(x, y, q);
  113. }
  114. for (int i=0; i<m; i++) {
  115. qq = i/float(m);
  116. y = y2;
  117. x = lerp(-sqrt(r*r-y*y), sqrt(r*r-y*y), qq);
  118. waveVertex(x, y, q);
  119. }
  120. for (int i=0; i<n; i++) {
  121. qq = i/float(n-1);
  122. y = lerp(y2, y1, qq);
  123. x = sqrt(r*r-y*y);
  124. waveVertex(x, y, q);
  125. }
  126. for (int i=0; i<m; i++) {
  127. qq = i/float(m);
  128. y = y1;
  129. x = lerp(sqrt(r*r-y*y), -sqrt(r*r-y*y), qq);
  130. waveVertex(x, y, q);
  131. }
  132. endShape();
  133. }
  134.  
  135. void draw_() {
  136. background(250);
  137. push();
  138. translate(width/2, height/2);
  139. fill(#30E0FF);
  140. circ(0);
  141. fill(#FD22F3);
  142. circ(TWO_PI/3);
  143. fill(#FFE210);
  144. circ(2*TWO_PI/3);
  145. pop();
  146. }
Add Comment
Please, Sign In to add comment