Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// by dave @ bees & bombs >:)
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 = 8;
int numFrames = 96;
float shutterAngle = .6;
boolean recording = true;
void setup_() {
size(500, 500);
noStroke();
}
int ns = 250;
float x, y;
void wave(int n, float h) {
beginShape();
vertex(width+2, 0);
vertex(-2, 0);
for (int i=0; i<ns; i++) {
x = map(i, 0, ns-1, -2, width+2);
y = map(sin(map(i, 0, ns-1, 0, n*PI)), -1, 1, height+h/2, height-h/2);
vertex(x, y);
}
endShape(CLOSE);
}
void draw_() {
background(0);
for (int i=-9; i<=9; i++) {
fill(255);
if (i%2 == 0)
fill(0);
pushMatrix();
translate(0, -height/2-32*i);
wave(abs(i)*2+1, 32*exp(-.17*abs(i))*cos(TWO_PI*t + PI*i));
popMatrix();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment