Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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 = 4;
int numFrames = 96;
float shutterAngle = .67;
boolean recording = true;
void setup_() {
size(750, 500, P2D);
smooth(8);
noStroke();
rectMode(CENTER);
}
float l = 30, tt;
float th, s, x, y;
int N = 18;
void draw_() {
t *= 1;
background(128);
pushMatrix();
translate(width/2, height/2);
scale(pow(.5, .5*t));
rotate(QUARTER_PI*t);
for (int i=-N; i<=N; i++) {
for (int j=-N; j<=N; j++) {
x = i*l;
y = j*l;
pushMatrix();
translate(x, y);
fill(0);
if ((i+j)%2 == 0)
fill(255);
rect(0, 0, l, l);
popMatrix();
}
}
for (int i=-N; i<=N; i++) {
for (int j=-N; j<=N; j++) {
x = i*l;
y = j*l;
tt = constrain(2.2*t - 1.15*dist(x, y, 0, 0)/470.0, 0, 1);
tt = pow(tt, .75);
s = l*sqrt(2)*tt;
th = QUARTER_PI*tt;
pushMatrix();
translate(x, y);
pushMatrix();
rotate(th);
fill(0);
if ((i+j)%2 == 0) {
rect(0, 0, s, s);
if (i%2 == 0) {
fill(255);
pushMatrix();
rect(0, 0, s*pow(max(0, 2*tt-1), .8), s*pow(max(0, 2*tt-1), .8));
popMatrix();
}
}
popMatrix();
popMatrix();
}
}
popMatrix();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment