Skip to content

Instantly share code, notes, and snippets.

Created March 11, 2014 09:09
Show Gist options
  • Save anonymous/9482096 to your computer and use it in GitHub Desktop.
Save anonymous/9482096 to your computer and use it in GitHub Desktop.
int[][] result;
float time;
void draw() {
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++) {
time = map(frameCount-1 + sa*shutterAngle/samplesPerFrame, 0, numFrames, 0, 1);
sample();
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();
frm = get();
filter(BLUR,7);
blend(frm,0,0,500,500,0,0,500,500,ADD);
saveFrame("f##.png");
if (frameCount==numFrames)
exit();
}
//////////////////////////////////////////////////////////////////////////////
int samplesPerFrame = 32;
int numFrames = 48;
float shutterAngle = .55;
PImage frm;
void setup() {
frm = new PImage(500,500);
size(500, 500, P2D);
fill(140);
noStroke();
smooth(8);
result = new int[width*height][3];
}
float t, r, tt, tt2, th, x, y, ll = 48;
int N = 12;
void sample() {
t = min(1, 1.25*time);
tt = pow(1-t, 2.2);
tt2 = pow(1-t, 3);
background(0);
pushMatrix();
translate(250, 250);
rotate(time*TWO_PI/(2*N) + TWO_PI/(2*N));
scale(pow(2, -time));
beginShape();
for (int i=0; i<(2*N); i++) {
r = ll + ll*(i%2);
th = i*TWO_PI/(2*N);
x = r*cos(th);
y = r*sin(th);
vertex(x, y);
}
endShape(CLOSE);
for (int i=0; i<N; i++) {
pushMatrix();
rotate(i*TWO_PI/N);
if (i%2 != 0) {
translate(0, -280);
rotate(-PI*tt2);
translate(0, 280);
}
else {
translate(0, -420);
rotate(-PI*tt);
translate(0, 420);
}
beginShape();
vertex(ll, 0);
vertex(2*ll*cos(TWO_PI/(2*N)), 2*ll*sin(TWO_PI/(2*N)));
vertex(4*ll, 0);
vertex(2*ll*cos(TWO_PI/(2*N)), -2*ll*sin(TWO_PI/(2*N)));
endShape(CLOSE);
popMatrix();
}
popMatrix();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment