Guest User

Untitled

a guest
Nov 18th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. OpenSimplexNoise noise;
  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("fr###.png");
  63. println(frameCount,"/",numFrames);
  64. if (frameCount==numFrames)
  65. exit();
  66. }
  67. }
  68.  
  69. //////////////////////////////////////////////////////////////////////////////
  70.  
  71. int samplesPerFrame = 1;
  72. int numFrames = 80;
  73. float shutterAngle = .8;
  74.  
  75. boolean recording = true;
  76.  
  77.  
  78.  
  79. void setup(){
  80. size(500,500);
  81. result = new int[width*height][3];
  82.  
  83. noise = new OpenSimplexNoise();
  84. }
  85.  
  86. int N = 40;
  87. float b = 50;
  88. float l = 10;
  89. float scl = 0.01;
  90. float r = 0.6;
  91.  
  92. void draw_(){
  93. background(0);
  94.  
  95. stroke(255);
  96. strokeWeight(2);
  97. for(int i=0;i<N;i++){
  98. for(int j=0;j<N;j++){
  99. float x = map(i,0,N-1,b,width-b);
  100. float y = map(j,0,N-1,b,height-b);
  101. float theta = 25*(float)noise.eval(scl*x,scl*y,r*cos(TWO_PI*t),r*sin(TWO_PI*t));
  102. float vx = l*cos(theta);
  103. float vy = l*sin(theta);
  104. float intensity = 0.1+1.5*ease(map((float)noise.eval(200+scl*x,scl*y,r*cos(TWO_PI*t),r*sin(TWO_PI*t)),-1,1,0,1),3.5);
  105. vx*=intensity;
  106. vy*=intensity;
  107. line(x,y,x+vx,y+vy);
  108. }
  109. }
  110.  
  111. }
Add Comment
Please, Sign In to add comment