daily pastebin goal
48%
SHARE
TWEET

Untitled

a guest Sep 21st, 2017 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.   }
  36.  
  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("f###.gif");
  63.     if (frameCount==numFrames)
  64.       exit();
  65.   }
  66. }
  67.  
  68. //////////////////////////////////////////////////////////////////////////////
  69.  
  70. int samplesPerFrame = 4;
  71. int numFrames = 240;        
  72. float shutterAngle = .6;
  73.  
  74. boolean recording = false;
  75.  
  76. void setup() {
  77.   size(800,600,P3D);
  78.   pixelDensity(recording ? 1 : 2);
  79.   smooth(8);
  80.   result = new int[width*height][3];
  81.   rectMode(CENTER);
  82.   noFill();
  83.   strokeWeight(17);
  84.   blendMode(ADD);
  85. }
  86.  
  87. float x, y, z, tt;
  88. int N = 15;
  89. color[] cs = { #FF2116, #01FF40, #0050E0 };
  90. float sp = 30, l = 440;
  91. float qq, th;
  92. int n = 40;
  93.  
  94. void thing(float q){
  95.   beginShape();
  96.   for(int i=0; i<n; i++){
  97.     qq = i/float(n-1);
  98.     x = 0;
  99.     y = lerp(-l/2,l/2,qq);
  100.     th = .35*sin(TWO_PI*q - HALF_PI*qq);
  101.     curveVertex(x*cos(th) + y*sin(th),y*cos(th) - x*sin(th));
  102.   }
  103.   endShape();
  104. }
  105.  
  106. void draw_() {
  107.   background(20);
  108.   push();
  109.   translate(width/2, height/2);
  110.   for(int i=-N; i<=N; i++){
  111.     tt = t + i/3.1;
  112.     push();
  113.     stroke(cs[(i+N)%3]);
  114.     translate(i*sp,0);
  115.     thing(tt);
  116.     pop();
  117.   }    
  118.   pop();
  119. }
RAW Paste Data
Top