Skip to content

Instantly share code, notes, and snippets.

@colbygk
Forked from anonymous/gist:bd7571a439bbaa36a397
Created September 1, 2014 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colbygk/1d9ec9196da6fbd3ea2f to your computer and use it in GitHub Desktop.
Save colbygk/1d9ec9196da6fbd3ea2f 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 | (result[i][0]/samplesPerFrame) << 16 |
(result[i][1]/samplesPerFrame) << 8 | (result[i][2]/samplesPerFrame);
updatePixels();
saveFrame("f###.gif");
if (frameCount==numFrames)
exit();
}
}
//////////////////////////////////////////////////////////////////////////////
int samplesPerFrame = 32;
int numFrames = 120;
float shutterAngle = .6;
boolean recording = true;
void setup_() {
size(500, 500);
noStroke();
}
int N = 8;
float dmax = 450, d;
float tt;
float pp = .5;
int nsegs;
void draw_() {
tt = 3*t*t - 2*t*t*t;
tt = 3*tt*tt - 2*tt*tt*tt;
background(0);
pushMatrix();
translate(width/2, height/2);
rotate(HALF_PI);
for (int i=N; i>=1; i--) {
d = map(pow(i,pp), pow(N,pp), 0, dmax, 0);
nsegs = int(pow(2, i));
fill(255);
ellipse(0, 0, d, d);
fill(0);
for (int a=0; a<nsegs; a++)
arc(0, 0, d+1, d+1, TWO_PI*(a+(N+1-i)*tt)/nsegs, TWO_PI*(a+(N+1-i)*tt+.5)/nsegs);
}
popMatrix();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment