Skip to content

Instantly share code, notes, and snippets.

@colbygk
Forked from anonymous/gist:d291b922c7bbee3f4ccd
Created September 1, 2014 03:03
Show Gist options
  • Save colbygk/c15e23610ae2d17e210c to your computer and use it in GitHub Desktop.
Save colbygk/c15e23610ae2d17e210c to your computer and use it in GitHub Desktop.
// by Dave @ beesandbombs
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 = 32;
int numFrames = 96;
float shutterAngle = .6;
boolean recording = true;
void setup_() {
size(500, 500);
smooth(8);
strokeWeight(1.5);
rectMode(CENTER);
}
int N = 6;
float x, y;
float l = 35;
float th;
float xx(int i, int j) {
return -j*l*sin(th) + i*l + i*l*cos(th);
}
float yy(int i, int j) {
return j*l + j*l*cos(th) + i*l*sin(th);
}
void draw_() {
th = PI/3.5*cos(TWO_PI*t);
background(42);
noStroke();
pushMatrix();
translate(width/2, height/2);
rotate(-th/3);
for (int j=-N; j<N; j++) {
for (int i=-N; i<N; i++) {
fill(248,245,238);
rect(xx(i, j), yy(i, j), l+1, l+1);
fill(240, 64, 32);
beginShape();
vertex(xx(i, j)-l/2, yy(i, j)-l/2);
vertex(xx(i, j)+l/2, yy(i, j)-l/2);
vertex(xx(i, j-1)+l/2, yy(i, j-1)+l/2);
vertex(xx(i, j-1)-l/2, yy(i, j-1)+l/2);
endShape();
fill(0, 128, 192);
beginShape();
vertex(xx(i, j)+l/2, yy(i, j)-l/2);
vertex(xx(i, j)+l/2, yy(i, j)+l/2);
vertex(xx(i+1, j)-l/2, yy(i+1, j)+l/2);
vertex(xx(i+1, j)-l/2, yy(i+1, j)-l/2);
endShape();
}
}
popMatrix();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment