Created
September 22, 2016 23:04
-
-
Save anonymous/176f4adb8ff2ce416bd18d12a03c3627 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// everything above ////// line is motion blur code | |
// when 'recording' is false, mouseX controls time | |
// when it's set to true, frames are saved | |
int[][] result; | |
float t, c; | |
float ease(float p) { | |
return 3*p*p - 2*p*p*p; | |
} | |
float ease(float p, float g) { | |
if (p < 0.5) | |
return 0.5 * pow(2*p, g); | |
else | |
return 1 - 0.5 * pow(2*(1 - p), g); | |
} | |
float mn = .5*sqrt(3); | |
void setup() { | |
setup_(); | |
result = new int[width*height][3]; | |
} | |
void draw() { | |
if (!recording) { | |
t = mouseX*1.0/width; | |
c = mouseY*1.0/height; | |
if (mousePressed) | |
println(c); | |
draw_(); | |
} else { | |
for (int i=0; i<width*height; i++) | |
for (int a=0; a<3; a++) | |
result[i][a] = 0; | |
c = 0; | |
for (int sa=0; sa<samplesPerFrame; sa++) { | |
t = map(frameCount-1 + sa*shutterAngle/samplesPerFrame, 0, numFrames, 0, 1); | |
draw_(); | |
loadPixels(); | |
for (int i=0; i<pixels.length; i++) { | |
result[i][0] += pixels[i] >> 16 & 0xff; | |
result[i][1] += pixels[i] >> 8 & 0xff; | |
result[i][2] += pixels[i] & 0xff; | |
} | |
} | |
loadPixels(); | |
for (int i=0; i<pixels.length; i++) | |
pixels[i] = 0xff << 24 | | |
int(result[i][0]*1.0/samplesPerFrame) << 16 | | |
int(result[i][1]*1.0/samplesPerFrame) << 8 | | |
int(result[i][2]*1.0/samplesPerFrame); | |
updatePixels(); | |
saveFrame("tu###.gif"); | |
if (frameCount==numFrames) | |
exit(); | |
} | |
} | |
////////////////////////////////////////////////////////////////////////////// | |
int samplesPerFrame = 32; | |
int numFrames = 200; | |
float shutterAngle = .4; | |
boolean recording = false; | |
void setup_() { | |
size(540, 540); | |
rectMode(CENTER); | |
fill(32); | |
noStroke(); | |
} | |
float x, y, tt; | |
int N = 5; | |
float d, D = 55, pp = 1.2; | |
float ttt; | |
PImage fr1, fr2; | |
int nCircs = 6; | |
PImage[] pims = new PImage[nCircs]; | |
void drawCircle(float q) { | |
if (q < .25) { | |
tt = 4*q; | |
tt = constrain(tt, 0.001, 0.999); // horrible hack | |
ttt = sq(tt); | |
background(255); | |
fill(0); | |
d = D*pow(1-ttt, -pp); | |
ellipse(-d/2+D/2-D/2*tt, 0, d, d); | |
} else if (q<.5) { | |
tt = 4*q - 1; | |
tt = constrain(tt, 0.001, 0.999); | |
ttt = 1 - sq(1-tt); | |
background(0); | |
fill(255); | |
d = D*pow(1-(1-ttt), -pp); | |
ellipse(d/2-D/2*tt, 0, d, d); | |
} else if (q < .75) { | |
tt = 4*q-2; | |
tt = constrain(tt, 0.001, 0.999); | |
ttt = sq(tt); | |
background(0); | |
fill(255); | |
d = D*pow(1-ttt, -pp); | |
ellipse(-d/2+D/2-D/2*tt, 0, d, d); | |
} else { | |
tt = 4*q - 3; | |
tt = constrain(tt, 0.001, 0.999); | |
ttt = 1 - sq(1-tt); | |
background(255); | |
fill(0); | |
d = D*pow(1-(1-ttt), -pp); | |
ellipse(d/2-D/2*tt, 0, d, d); | |
} | |
} | |
void draw_() { | |
background(250); | |
pushMatrix(); | |
translate(width/2, height/2); | |
for (int i=0; i<nCircs; i++) { | |
pushMatrix(); | |
rotate(TWO_PI*i/nCircs); | |
translate(0, 150); | |
drawCircle((t+100-0.5*i/(nCircs))%1); | |
popMatrix(); | |
pims[i] = get(); | |
} | |
background(0); | |
for (int i=0; i<nCircs; i++) | |
blend(pims[i], 0, 0, width, height, 0, 0, width, height, DIFFERENCE); | |
popMatrix(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment