Skip to content

Instantly share code, notes, and snippets.

Created January 27, 2014 20:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/8656313 to your computer and use it in GitHub Desktop.
Save anonymous/8656313 to your computer and use it in GitHub Desktop.
squarez
int samplesPerFrame = 32;
int numFrames = 48;
float shutterAngle = .8;
int[][] result;
float time;
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);
sample();
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();
}
void setup() {
size(500, 500);
result = new int[width*height][3];
rectMode(CENTER);
noStroke();
}
float l = 400, d, a, t;
void sample() {
if (time <= .5) {
t = 2*time;
t = 3*t*t - 2*t*t*t;
t = 3*t*t - 2*t*t*t;
a = map(t,0,1,0,QUARTER_PI);
d = sqrt(2)*.5*l/cos(a);
background(255);
pushMatrix();
translate(width/2, height/2);
fill(0);
rect(0, 0, l, l);
for (int i=0; i<20; i++) {
fill(255*((i+1)%2));
pushMatrix();
rotate(QUARTER_PI*(i+1)+a);
rect(0, 0, d*pow(sqrt(2), -i), d*pow(sqrt(2), -i));
popMatrix();
}
popMatrix();
}
else {
t = 2*time - 1;
t = 3*t*t - 2*t*t*t;
t = 3*t*t - 2*t*t*t;
a = map(t,0,1,0,QUARTER_PI);
d = l/cos(a);
background(255);
pushMatrix();
translate(width/2, height/2);
for (int i=0; i<20; i++) {
fill(255*((i+1)%2));
pushMatrix();
rotate(QUARTER_PI*i+a);
rect(0, 0, d*pow(sqrt(2), -i), d*pow(sqrt(2), -i));
popMatrix();
}
popMatrix();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment