Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. // by Etienne JACOB
  2. // uses a formula inspired by @ozachou_g (on twitter)
  3.  
  4. //click on canvas to generate a new one
  5. //press key to save
  6.  
  7. float x,y,z,t;
  8.  
  9. float[] A = new float[12];
  10. float[] f = new float[12];
  11. float[] ph = new float[12];
  12.  
  13. int N;
  14. float rot0,v;
  15.  
  16. int frame = 0;
  17.  
  18. void initialize(){
  19. frame = 0;
  20.  
  21. for(int i=0;i<12;i++){
  22. A[i] = random(-3.0,3.0);
  23. f[i] = random(-1.2,1.2);
  24. ph[i] = random(TWO_PI);
  25. }
  26.  
  27. x = random(-1,1);
  28. y = random(-1,1);
  29. z = random(-1,1);
  30.  
  31. t = 0;
  32.  
  33. v = 0.0000001*pow(10,random(5));
  34.  
  35. background(235);
  36.  
  37. rot0 = random(TWO_PI);
  38. N = floor(random(5,15));
  39. }
  40.  
  41. void setup() {
  42. //createCanvas(windowWidth, windowHeight);
  43. size(1000, 1000, P2D);
  44.  
  45. initialize();
  46. }
  47.  
  48. void move(){
  49. float xx = A[0]*sin(f[0]*x+ph[0]) + A[1]*cos(f[1]*y+ph[1]) + 2*A[2]*sin(f[2]*t+ph[2]) + A[3]*sin(f[3]*z+ph[3]);
  50. float yy = A[4]*cos(f[4]*x+ph[4]) + A[5]*sin(f[5]*y+ph[5]) + 2*A[6]*cos(f[6]*t+ph[6]) + A[7]*sin(f[7]*z+ph[7]);
  51. float zz = A[8]*sin(f[8]*x+ph[8]) + A[9]*cos(f[9]*y+ph[9]) + 2*A[10]*sin(f[10]*t+ph[10]) + A[11]*cos(f[11]*z+ph[11]);
  52. float tt = t + v;
  53.  
  54. x = xx;
  55. y = yy;
  56. z = zz;
  57. t = tt;
  58. }
  59.  
  60. void step(){
  61. move();
  62.  
  63. float scale = 0.2;
  64.  
  65. float F = 0.5;
  66.  
  67. float xx = scale*sin(F*x);
  68. float yy = scale*sin(F*y);
  69. float zz = scale*sin(F*z);
  70.  
  71. stroke(0,4);
  72.  
  73. if(-zz+zdist>0){
  74. PVector proj = projection(xx,yy,zz);
  75.  
  76. for(int r=0;r<N;r++){
  77. pushMatrix();
  78.  
  79. translate(width/2,height/2);
  80. rotate(TWO_PI*r/N + 0*rot0);
  81.  
  82. strokeWeight(1+random(0,0.35)*proj.z);
  83.  
  84. float std = 0.25;
  85.  
  86. point(proj.x+std*randomGaussian(),proj.y+std*randomGaussian());
  87.  
  88. popMatrix();
  89. }
  90. }
  91. }
  92.  
  93. float zdist = 0.4;
  94.  
  95. PVector projection(float xx,float yy,float zz){
  96. float inv = 1.0/(-zz+zdist);
  97. float xxx = 300*xx*inv;
  98. float yyy = 300*yy*inv;
  99. return new PVector(xxx,yyy,inv);
  100. }
  101.  
  102. void saveF(){
  103. println("saving");
  104. saveFrame("res"+floor(random(1000000))+".png");
  105. //stop();
  106. }
  107.  
  108. void keyPressed() {
  109. saveF();
  110. }
  111.  
  112. void mousePressed(){
  113. initialize();
  114. }
  115.  
  116. int numFrames = 50;
  117.  
  118. int K = 8500;
  119.  
  120. void draw() {
  121. frame++;
  122.  
  123. for(int k=0;k<K;k++){
  124. step();
  125. }
  126.  
  127. println(frame,'/',numFrames);
  128.  
  129. if(frame==numFrames){
  130. saveF();
  131. }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement