Skip to content

Instantly share code, notes, and snippets.

Created January 27, 2014 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/8656012 to your computer and use it in GitHub Desktop.
Save anonymous/8656012 to your computer and use it in GitHub Desktop.
cool gif code >:)
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();
}
////////////////////////////////////////////////////////////////////////////
int samplesPerFrame = 32;
int numFrames = 48;
float shutterAngle = .6;
void setup() {
size(500, 500);
result = new int[width*height][3];
noStroke();
}
float r1, r2, th1, th2, pp = .667, t, q = .5;
int N = 12, M;
void sample() {
t = time;
background(255);
fill(0);
pushMatrix();
translate(width/2, height/2);
for(int i=1; i<N; i++){
r1 = map(pow(i,pp)+q*sin(TWO_PI*t + 0.5*i),0,pow(N,pp),0,500);
r2 = map(pow(i+1,pp)+q*sin(TWO_PI*t + 0.5*(i+1)),0,pow(N,pp),0,500);
M = int(1.5*pow(2,i));
for(int j=0; j<M; j++){
th1 = map(j,0,M,0,TWO_PI);
th2 = map(j+1,0,M,0,TWO_PI);
triangle(r1*cos(th1), r1*sin(th1),
r1*cos(th2), r1*sin(th2),
r2*cos(0.5*(th1+th2)), r2*sin(0.5*(th1+th2)));
}
}
popMatrix();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment