Advertisement
xeromino

collab3

Oct 19th, 2014
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.66 KB | None | 0 0
  1. // Code by @MetaGlitch
  2.  
  3. float fps = 16.666;
  4.  
  5. int inFrames = 15;
  6. int outFrames = 15;
  7. int otherFrames = 60;
  8. int numFrames = inFrames + otherFrames + outFrames;
  9.  
  10. float t1 = inFrames * 1.0/numFrames;
  11. float t2 = (inFrames+otherFrames) * 1.0/numFrames;
  12.  
  13. int samplesPerFrame = 8;
  14. float exposure = 0.75; // exposure time in frames. >1 allowed for blending multiple frames
  15. float subFrameAttenuation = 1; // 1 for weighting every subframe the same. <1 for attenuation effect.
  16. boolean looping = true; // false: t=1 on the last frame; true: t=1-1/nummFrames on last frame.
  17.  
  18. boolean recording = true;
  19.  
  20. float a = 0;
  21. float s = TWO_PI/120;
  22.  
  23. void setup_() {
  24.   size(500, 500, P3D);
  25.   smooth(8);
  26.   noStroke();
  27.   noiseDetail(4);
  28.   rectMode(CENTER);
  29. }
  30.  
  31. float exposureCopy = exposure;
  32. void draw_() {
  33.   // collab settings: hit t=1 and remove motion blur on first and last frame.
  34.   looping = false;
  35.   if (frameCount==1 || frameCount==numFrames) exposure=0;
  36.   else exposure=exposureCopy;
  37.  
  38.   background(255);
  39.  
  40.  
  41.   float x = 250;
  42.   float y = 0;
  43.   float sz = 100;
  44.   float sz2 = 0;
  45.   if (t<t1) {
  46.     y = map(t, 0, t1, -50, 50); // entry
  47.     fill(0);
  48.     ellipse(x, y, sz, sz);
  49.   }
  50.   if (t>t2) {
  51.     y = map(t, t2, 1, 450, 550);
  52.     fill(0);
  53.     ellipse(x, y, sz, sz);// exit
  54.   }
  55.   if (t>=t1 && t<=t2) {  // stuff by p5art
  56.     y = map(t, t1, t2, 50, 450);
  57.     x = 250; // + random(-5, 5);
  58.     float temp = map(t, t1, t2, PI, TWO_PI+PI);
  59.     sz = map(cos(temp), -1, 1, 100, 300);
  60.     sz2 = map(cos(temp), -1, 1, 0, sz*.75);
  61.     fill(0);
  62.     float corner= map(cos(temp), -1, 1, sz,0);
  63.     float corner2= map(cos(temp), -1, 1, sz2,0);
  64.     rect(x,y,sz,sz,corner);
  65.     fill(255);
  66.     rect(x,y,sz2,sz2,corner2);
  67.   }
  68.   a+=s;
  69. }
  70.  
  71. //////////////////
  72.  
  73. float pingpong(float t) { //  / => /\
  74.   return 1-2*abs(t-0.5);
  75. }
  76.  
  77. float ease(float t, float e) {
  78.   return t < 0.5 ? 0.5 * pow(2*t, e) : 1 - 0.5 * pow(2*(1 - t), e);
  79. }
  80.  
  81. float ease(float t, float in, float out) {
  82.   return (1-t)*ease(t, in) + t*ease(t, out);
  83. }
  84.  
  85. float randomC() {
  86.   float r = random(0, 1);
  87.   float ang = sin(TWO_PI*random(0, 1));
  88.   return r*ang;
  89. }
  90.  
  91. // Code by @MetaGlitch
  92.  
  93. float t;
  94. float[][] result;
  95.  
  96. void setup() {
  97.   setup_();
  98.   result = new float[width*height][3];
  99. }
  100.  
  101. void draw() {
  102.   if (!recording) {
  103.     if (mousePressed) {
  104.       frameRate(60);
  105.       t = mouseX*1.0/width;
  106.       if (mouseButton == LEFT) t = constrain(t, 0, 1);
  107.       while(t<0) t+=1.0;
  108.       while(t>1) t-=1.0;
  109.     } else {
  110.       frameRate(fps);
  111.       t = float((frameCount-1)%numFrames) / numFrames;
  112.     }
  113.     draw_();  
  114.   } else { // sub frame rendering inspired by @beesandbombs
  115.     for (int i=0; i<width*height; i++) for (int a=0; a<3; a++) result[i][a] = 0;
  116.  
  117.     float divider = 0;
  118.     for (int sa=0; sa<samplesPerFrame; sa++) {
  119.       noLights(); // reset lights
  120.       t = map(frameCount-1 + exposure*sa/samplesPerFrame, 0, numFrames - (looping?0:1) , 0, 1) % 1;
  121.       pushMatrix();
  122.       draw_();
  123.       popMatrix();
  124.       loadPixels();
  125.       float weight = pow(subFrameAttenuation, samplesPerFrame-sa-1);
  126.       divider += weight;
  127.       for (int i=0; i<pixels.length; i++) {
  128.         result[i][0] += weight * (pixels[i] >> 16 & 0xff);
  129.         result[i][1] += weight * (pixels[i] >> 8 & 0xff);
  130.         result[i][2] += weight * (pixels[i] & 0xff);
  131.       }
  132.     }
  133.  
  134.     loadPixels();
  135.     for (int i=0; i<pixels.length; i++)
  136.       pixels[i] = 0xff << 24 |
  137.         int(result[i][0]*1.0/divider) << 16 |
  138.         int(result[i][1]*1.0/divider) << 8 |
  139.         int(result[i][2]*1.0/divider);
  140.     updatePixels();
  141.  
  142.     //saveFrame("frames/f###.png");
  143.     if (frameCount==numFrames)
  144.       exit();
  145.   }
  146.  
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement