Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 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 = 2;
  69. int numFrames = 140;
  70. float shutterAngle = .4;
  71.  
  72. boolean recording = false;
  73.  
  74. void setup() {
  75. size(720, 720, P3D);
  76. strokeWeight(3);
  77. smooth(8);
  78. result = new int[width*height][3];
  79. rectMode(CENTER);
  80. stroke(32);
  81. noFill();
  82. }
  83.  
  84. float x, y, z, tt;
  85. float th, r, p;
  86. int N, nw;
  87.  
  88. int in;
  89.  
  90. float q(float x_, float y_){
  91. in = constrain(int(y_+height/2)*width + int(x_+width/2),0,img.pixels.length-1);
  92. return red(img.pixels[in])/255.0;
  93. }
  94.  
  95. void thing(float r_) {
  96. N = int(2.5*r_);
  97. nw = int(.32*r_);
  98. beginShape();
  99. for (int i=0; i<N; i++) {
  100. th = i*TWO_PI/N;
  101. x = r_*cos(th);
  102. y = r_*sin(th);
  103. p = q(x,y);
  104. r = r_ + 7*p*cos(nw*th - TWO_PI*int(.025*r_+1)*t);
  105. vertex(r*cos(th), r*sin(th));
  106. }
  107. endShape(CLOSE);
  108. }
  109.  
  110. PImage img;
  111.  
  112. void draw_() {
  113. push();
  114. translate(width/2,height/2);
  115. background(0);
  116. fill(255);
  117. noStroke();
  118. rotate(-TWO_PI/3*t);
  119. beginShape();
  120. for(int i=0; i<3; i++)
  121. vertex(315*cos(TWO_PI*i/3),315*sin(TWO_PI*i/3));
  122. endShape();
  123. pop();
  124. filter(BLUR,6);
  125. img = get();
  126. img.loadPixels();
  127. background(0);
  128. stroke(40,180,240);
  129. push();
  130. translate(width/2, height/2);
  131. for (int i=0; i<20; i++)
  132. thing(30+25*i);
  133. pop();
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement