Skip to content

Instantly share code, notes, and snippets.

@eqx
Created August 28, 2016 23:56
Show Gist options
  • Save eqx/22df0fe9cca7252b9eda8e27be04cc02 to your computer and use it in GitHub Desktop.
Save eqx/22df0fe9cca7252b9eda8e27be04cc02 to your computer and use it in GitHub Desktop.
int[][] result;
float t;
void setup() {
setup_();
result = new int[width*height][3];
}
void draw() {
if (!recording) {
t = mouseX*1.0/width;
draw_();
} else {
for (int i=0; i<width*height; i++)
for (int a=0; a<3; a++)
result[i][a] = 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("f###.gif");
if (frameCount==numFrames)
exit();
}
}
//////////////////////////////////////////////////////////////////////////////
int samplesPerFrame = 32;
int numFrames = 120;
float shutterAngle = .6;
boolean recording = false;
void setup_() {
size(800, 600, P2D);
smooth(8);
noStroke();
}
boolean shadow;
float x, y, tt, d;
int N = 200, n = 10;
void spiral() {
pushMatrix();
translate(width/2, height/2);
rotate(-HALF_PI);
for (int i=0; i<N; i++) {
pushMatrix();
scale(.9*exp(-.052*(i-n*t)));
rotate(TWO_PI*i/(n+.5)+TWO_PI*t/(2*n+1));
tt = 0;
if (i<2*n) {
tt = t + .5 - i/float(n);
tt = constrain(2*tt, 0, 1);
tt = pow(tt, 3.5);
}
translate(650*tt, 0);
d = 100*exp(-.75*tt);
if (shadow)
d*=1.05;
ellipse(200, 0, d, d);
popMatrix();
}
popMatrix();
}
void draw_() {
background(#A57FAE);
fill(lerpColor(#A57FAE, #000000, .175));
shadow = true;
pushMatrix();
translate(2, 2.5);
spiral();
popMatrix();
shadow = false;
fill(255);
spiral();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment