Skip to content

Instantly share code, notes, and snippets.

Created August 20, 2014 21:51
Show Gist options
  • Save anonymous/e7e1c1d406eb742da10a to your computer and use it in GitHub Desktop.
Save anonymous/e7e1c1d406eb742da10a to your computer and use it in GitHub Desktop.
// by dw @ bees & bombs
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 |
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 = 8;
int numFrames = 120;
float shutterAngle = .6;
boolean recording = false;
void setup_() {
size(500, 500, P2D);
smooth(8);
fill(32);
noStroke();
}
void leaf() {
bezier(0, 0, 42, 0, 15, 27, 0, 50);
bezier(0, 0, -42, 0, -15, 27, 0, 50);
}
float x, y, tt;
int N = 5;
float t1;
void draw_() {
background(250);
pushMatrix();
translate(width/2, height/2);
rotate(QUARTER_PI);
for (int a=-1; a<8; a++) {
t1 = .16*(t+a);
if (0<=t1 && t1<=1) {
N = 2*int(4*pow(2, int(5*t1)));
for (int i=0; i<N; i++) {
tt = (5*t1)%1;
tt = max(0, 1.7*tt-.7);
tt = 3*tt*tt - 2*tt*tt*tt;
pushMatrix();
rotate(TWO_PI/N);
rotate(-PI*tt/N);
rotate(2*TWO_PI*(i/2)/N);
if (i%2 == 0)
rotate(TWO_PI*tt/N);
translate(0, -2+350*pow(t1,1));
scale(pow(4, -t1));
if(t1<=.12)
scale(pow(sin(HALF_PI*t1/.12),.85));
scale(1,pow(1+.5*t1,.8));
leaf();
popMatrix();
}
}
}
popMatrix();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment