Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. //using code 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. }
  38.  
  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("frame-###.png");
  65. if (frameCount==numFrames)
  66. exit();
  67. }
  68. }
  69.  
  70. //////////////////////////////////////////////////////////////////////////////
  71.  
  72. int samplesPerFrame = 8;
  73. int numFrames = 200;
  74. float shutterAngle = .9;
  75.  
  76. boolean recording = false;
  77.  
  78. int n = 500;
  79. float r = 50;
  80.  
  81. float x(float q){
  82. return r*(sin(q) + 2*sin(2*q));
  83. }
  84.  
  85. float y(float q){
  86. return r*(cos(q) - 2*cos(2*q));
  87. }
  88.  
  89. float h = 1e-4;
  90.  
  91. float xp(float q){
  92. return r*(cos(q)+4*cos(2*q));
  93. }
  94.  
  95. float yp(float q){
  96. return -r*(sin(q)-4*sin(2*q));
  97. }
  98.  
  99. float xpp(float q){
  100. return (xp(q+h/2)-xp(q-h/2))/h;
  101. }
  102.  
  103. float ypp(float q){
  104. return (yp(q+h/2)-yp(q-h/2))/h;
  105. }
  106.  
  107. float xpn(float q){
  108. return xp(q)/dist(xp(q),yp(q),0,0);
  109. }
  110.  
  111. float ypn(float q){
  112. return yp(q)/dist(xp(q),yp(q),0,0);
  113. }
  114.  
  115. float th;
  116.  
  117. void drawCurve(){
  118. stroke(255);
  119. noFill();
  120. beginShape();
  121. for(int i=0; i<n; i++){
  122. th = TWO_PI*i/n;
  123. vertex(x(th),y(th));
  124. }
  125. endShape(CLOSE);
  126. }
  127.  
  128. float radius,xd,yd,xx,yy;
  129.  
  130. void drawDisk(){
  131. th = TWO_PI*t;
  132. radius = pow(xp(th)*xp(th)+yp(th)*yp(th),1.5)/(xp(th)*ypp(th) - xpp(th)*yp(th));
  133. xd = x(th) - ypn(th)*radius;
  134. yd = y(th) + xpn(th)*radius;
  135. xx = x(th);
  136. yy = y(th);
  137. noStroke();
  138. fill(255);
  139. ellipse(xd,yd,2*radius-7,2*radius-7);
  140. ellipse(xx,yy,5,5);
  141.  
  142. }
  143.  
  144. void setup() {
  145. size(640,640);
  146. result = new int[width*height][3];
  147. rectMode(CENTER);
  148. stroke(255);
  149. noFill();
  150. strokeWeight(7);
  151. }
  152.  
  153. void draw_() {
  154. background(0);
  155. push();
  156. translate(width/2,height/2);
  157. blendMode(BLEND);
  158. drawCurve();
  159. push();
  160. blendMode(EXCLUSION);
  161. drawDisk();
  162. pop();
  163. pop();
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement