Skip to content

Instantly share code, notes, and snippets.

Created April 23, 2014 22:48
Show Gist options
  • Save anonymous/11235185 to your computer and use it in GitHub Desktop.
Save anonymous/11235185 to your computer and use it in GitHub Desktop.
int[][] result;
float time;
void setup() {
setup_();
result = new int[width*height][3];
}
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);
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###.png");
if (frameCount==numFrames)
exit();
}
//////////////////////////////////////////////////////////////////////////////
int samplesPerFrame = 16;
int numFrames = 111;
float shutterAngle = .45;
float r = 175, d, dd, y, z, df;
int N = 30;
void setup_() {
size(500, 500, P3D);
smooth(8);
strokeWeight(2.8);
fill(255); stroke(77);
}
void draw_() {
background(255);
pushMatrix();
translate(width/2, height/2, -50);
rotateX(-.2);
rotateY(-PI/6);
for (int i=0; i<N; i++) {
z = map(i, -0.5, N-.5, -r, r);
d = sqrt(4*r*r - 4*z*z);
df = map(cos(TWO_PI*time),1,-1,1,.2);
dd = map(sin(TWO_PI*time + HALF_PI*i/N), -1, 1, d*df, d);
y = .5*(d - dd)*sin(2*TWO_PI*time + PI*i/N + PI*i);
pushMatrix();
translate(0, 0, z);
ellipse(0, y, dd, dd);
popMatrix();
}
popMatrix();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment