Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
circles
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] =color(result[i][0]*1.0/samplesPerFrame,
result[i][1]*1.0/samplesPerFrame, result[i][2]*1.0/samplesPerFrame);
updatePixels();
saveFrame("f###.gif");
if (frameCount==numFrames)
exit();
}
}
//////////////////////////////////////////////////////////////////////////////
int samplesPerFrame = 4;
int numFrames = 96;
float shutterAngle = .75;
boolean recording = false;
void setup_() {
size(500, 500, P2D);
smooth(8);
noFill();
strokeWeight(2);
stroke(32);
}
float d = 72, sp;
float x, y;
int N = 9;
float ts, tt;
void draw_() {
ts = 3*t*t - 2*t*t*t; // ts determines the spacing
ts = 3*ts*ts - 2*ts*ts*ts;
sp = .5*d*pow(2, ts);
background(250);
pushMatrix();
translate(width/2, height/2);
for (int i=-N; i<=N; i++) {
for (int j=-N; j<=N; j++) {
x = i*sp;
y = j*.5*sqrt(3)*sp;
if (j%2 != 0)
x += .5*sp;
tt = constrain(1.8*t - 0.0008*dist(x, y, 0, 0) - 0.5, 0, 1); // tt determines the completion of the new circles
tt = 3*tt*tt - 2*tt*tt*tt;
tt = .5*tt + 1.5*tt*tt - tt*tt*tt;
if (j%2 != 0 || (i+j/2)%2 != 0)
arc(x, y, d, d, -atan2(x, y) + HALF_PI, -atan2(x, y) + HALF_PI+TWO_PI*tt);
else
ellipse(x, y, d, d);
}
}
popMatrix();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment