daily pastebin goal
20%
SHARE
TWEET

Untitled

a guest Jan 17th, 2018 62 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. float c01(float g) {
  28.   return constrain(g, 0, 1);
  29. }
  30.  
  31. void draw() {
  32.  
  33.   if (!recording) {
  34.     t = mouseX*1.0/width;
  35.     c = mouseY*1.0/height;
  36.     if (mousePressed)
  37.       println(c);
  38.     draw_();
  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("f###.gif");
  65.     if (frameCount==numFrames)
  66.       exit();
  67.   }
  68. }
  69.  
  70. //////////////////////////////////////////////////////////////////////////////
  71.  
  72. int samplesPerFrame = 8;
  73. int numFrames = 120;        
  74. float shutterAngle = 1;
  75.  
  76. boolean recording = false;
  77.  
  78. void setup() {
  79.   size(800, 600, P3D);
  80.   smooth(8);
  81.   result = new int[width*height][3];
  82.   rectMode(CENTER);
  83.   fill(255);
  84.   noStroke();
  85.   blendMode(EXCLUSION);
  86. }
  87.  
  88. float x, y, z, tt;
  89. int N = 12;
  90. float r = 40, sp = 2*r*mn;
  91.  
  92. PImage f1, f2, f3;
  93.  
  94. void tri(){
  95.   beginShape();
  96.   for(int i=0; i<3; i++)
  97.     vertex(r*sin(TWO_PI*i/3), r*cos(TWO_PI*i/3));
  98.   endShape();
  99. }
  100.  
  101. void drawTris(){
  102.   for (int i=-N; i<N; i++) {
  103.     for (int j=-N; j<N; j++) {
  104.       x = i*sp;
  105.       y = j*mn*sp;
  106.       if(j%2 != 0)
  107.         x += .5*sp;
  108.       push();
  109.       translate(x,y);
  110.       rotate(HALF_PI);
  111.       scale(pow(2,0.5+0.5*cos(TWO_PI*t - 0.01*dist(x,y,0,0))));
  112.       tri();
  113.       pop();
  114.     }
  115.   }
  116. }
  117.  
  118. void draw_() {
  119.   blendMode(EXCLUSION);
  120.   background(0);
  121.   push();
  122.   translate(width/2, height/2);
  123.   rotate(-HALF_PI);
  124.  
  125.   drawTris();
  126.   f1 = get();
  127.  
  128.   background(0);
  129.   push();
  130.   scale(1.006);
  131.   drawTris();
  132.   pop();
  133.   f2 = get();
  134.  
  135.   background(0);
  136.   push();
  137.   scale(1.012);
  138.   drawTris();
  139.   pop();
  140.   f3 = get();
  141.  
  142.   pop();
  143.  
  144.   background(0);
  145.   loadPixels();
  146.   f1.loadPixels();
  147.   f2.loadPixels();
  148.   f3.loadPixels();
  149.  
  150.   for(int i=0; i<pixels.length; i++)
  151.     pixels[i] = color(20+.9*red(f1.pixels[i]),20+.9*green(f2.pixels[i]),20+.9*blue(f3.pixels[i]));
  152.   updatePixels();
  153. }
RAW Paste Data
Top