Skip to content

Instantly share code, notes, and snippets.

Created August 31, 2014 00:02
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save anonymous/5fc03656ea1b7ffb6f56 to your computer and use it in GitHub Desktop.
Save anonymous/5fc03656ea1b7ffb6f56 to your computer and use it in GitHub Desktop.
//by dave @ bees & bombs
int[][] result;
float t;
float ease(float p) {
return 3*p*p - 2*p*p*p;
}
float ease(float p, float g) { // via patakk >:)
if (p < 0.5)
return 0.5 * pow(2*p, g);
else
return 1 - 0.5 * pow(2*(1 - p), g);
}
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 |
int(result[i][0]*1.0/samplesPerFrame) << 16 |
int(result[i][1]*1.0/samplesPerFrame) << 8 |
int(result[i][2]*1.0/samplesPerFrame);
updatePixels();
saveFrame("f###.gif");
if (frameCount==numFrames)
exit();
}
}
//////////////////////////////////////////////////////////////////////////////
int samplesPerFrame = 16;
int numFrames = 200;
float shutterAngle = 1;
boolean recording = false;
void setup_() {
size(500, 500, P3D);
smooth(8);
perspective(0.35,1,100,1000);
stroke(32);
noFill();
}
float x, y, tt;
int N = 5;
float l = 52, q = -.33;
void box1() {
for (int i=0; i<4; i++) {
pushMatrix();
rotateY(HALF_PI*i);
line(-l/2-q, -l/2-q, l/2+q, l/2+q, l/2+q, l/2+q);
line(l/2+q, -l/2-q, l/2+q, -l/2-q, l/2+q, l/2+q);
popMatrix();
}
for (int i=0; i<4; i++) {
pushMatrix();
rotateX(PI*i);
line(-l/2-q, l/2+q, -l/2-q, l/2+q, l/2+q, l/2+q);
line(l/2+q, l/2+q, -l/2-q, -l/2-q, l/2+q, l/2+q);
popMatrix();
}
}
int nl = 12;
float ll = .5;
void box2() {
for (int a=0; a<4; a++) {
pushMatrix();
rotateY(HALF_PI*a);
for (int i=0; i<nl; i++)
line(map(i, 0, nl-1+ll, -l/2, l/2), l/2, l/2, map(i+ll, 0, nl-1+ll, -l/2, l/2), l/2, l/2);
popMatrix();
}
for (int a=0; a<4; a++) {
pushMatrix();
rotateY(HALF_PI*a);
for (int i=0; i<nl; i++)
line(map(i, 0, nl-1+ll, -l/2, l/2), -l/2, l/2, map(i+ll, 0, nl-1+ll, -l/2, l/2), -l/2, l/2);
popMatrix();
}
for (int a=0; a<4; a++) {
pushMatrix();
rotateY(HALF_PI*a);
for (int i=0; i<nl; i++)
line(l/2, map(i, 0, nl-1+ll, -l/2, l/2), l/2, l/2, map(i+ll, 0, nl-1+ll, -l/2, l/2), l/2);
popMatrix();
}
}
void draw_() {
tt = ease((3*t)%1,4.5);
background(250);
pushMatrix();
translate(width/2, height/2);
rotateX(-atan(sqrt(.5)));
rotateY(QUARTER_PI);
if (t <= 1/3.0)
rotateX(-HALF_PI*tt);
else if (t <= 2/3.0)
rotateY(-HALF_PI*tt);
else
rotateZ(HALF_PI*tt);
strokeWeight(3.5);
box1();
strokeWeight(1.25);
box2();
popMatrix();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment