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 = 16;
int numFrames = 150;
float shutterAngle = .5;
boolean recording = true;
void setup_() {
size(500, 500);
fill(245);
noStroke();
}
float d = 24, sp = 1.67*d;
int N = 12;
float mn = .5*sqrt(3);
float tt, ttt;
float x, y;
int step;
void draw_() {
background(24);
tt = (3*t)%1;
step = floor(3*t);
pushMatrix();
translate(width/2, height/2);
rotate(TWO_PI*step/3);
for (int i=-N; i<=N; i++) {
for (int j=-N; j<=N; j++) {
x = i*sp;
y = j*mn*sp;
if (j%2 != 0)
x += .5*sp;
if (step >= 1) {
x -= .25*sp;
y-=.5*mn*sp;
}
if (step == 2) {
x += .25*sp;
y-=.5*mn*sp;
}
ttt = constrain(2.5*tt - 1.5*dist(x, y, 0, 0)/370.0, 0, 1);
ttt = 3*ttt*ttt - 2*ttt*ttt*ttt;
ttt = .5*ttt + 1.5*ttt*ttt - ttt*ttt*ttt;
if (j%2 != 0)
x -= .5*sp*ttt;
else
x += .5*sp*ttt;
ellipse(x, y, d, d);
}
}
popMatrix();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment