Skip to content

Instantly share code, notes, and snippets.

Created January 28, 2014 19:07
Show Gist options
  • Save anonymous/8674048 to your computer and use it in GitHub Desktop.
Save anonymous/8674048 to your computer and use it in GitHub Desktop.
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();
}
//////////////////////////////////////////////////////////////////////////////////
float xci(float q) {
return 1.15*cos(TWO_PI*q);
}
float yci(float q) {
return 1.15*sin(TWO_PI*q);
}
float ysq(float q) {
if (.125<=q && q<=.375)
return 1;
else if (q>=.625 && q<=.875)
return -1;
else if (q>=.375 && q<=.625)
return map(q, .375, .625, 1, -1);
else
return map((q+.125)%1, 0, .25, -1, 1);
}
float xsq(float q) {
if ((q<=.125) || (0.875<=q))
return 1;
else if (q>=.375 && q<=.625)
return -1;
else if (q >= .125 && q<= .375)
return map(q, .125, .375, 1, -1);
else
return map(q, .625, .875, -1, 1);
}
void thing(float ppp) {
pushMatrix();
scale(map(ppp, 0, 1, 1, 1.1));
beginShape();
for (int i=0; i<M; i++) {
th = i*TWO_PI/M;
x = l*pow(abs(sin(th)), ppp);
if (th >= PI)
x *= -1;
y = l*pow(abs(cos(th)), ppp);
if (th >= HALF_PI && th <= PI*3/2)
y *= -1;
vertex(x, y);
}
endShape();
popMatrix();
}
int samplesPerFrame = 32;
int numFrames = 48;
float shutterAngle = .75;
void setup() {
size(500, 500);
result = new int[width*height][3];
noStroke();
}
float p, tt;
int N = 16, M = 64;
float xp, yp, x, y;
float l = 0.11;
float th;
void sample() {
background(0);
for (int a=0; a<20; a++) {
fill(255*pow(0.86,(a-2*time)));
pushMatrix();
translate(250, 250);
scale(250*pow(0.65,(a-2*time)));
tt = map(cos(TWO_PI*time + 0.5*(a-2*time)), -1, 1, 0, 1);
tt = 3*tt*tt - 2*tt*tt*tt;
for (int i=0; i<N; i++) {
p = (i+time*((a%2)*2-1))/float(N);
xp = lerp(xsq(p), xci(p), tt);
yp = lerp(ysq(p), yci(p), tt);
pushMatrix();
translate(xp, yp);
thing(tt);
popMatrix();
}
popMatrix();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment