Created
July 13, 2014 11:39
-
-
Save anonymous/ee11d161ad56a5a576fe to your computer and use it in GitHub Desktop.
Revisions
-
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,114 @@ 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 = 8; int numFrames = 120; float shutterAngle = .75; boolean recording = false; void setup_() { size(500, 500, P2D); smooth(8); noStroke(); } color[] cols = { #ee4411, #55bb66, #3300cc }; void diam() { beginShape(); vertex(0, .1); vertex(r*mn, -r*.5); vertex(0, -r); vertex(-r*mn, -r*.5); endShape(CLOSE); } float r = 24; float x, y, sp = 3.725*r; float tt; float t1, t2; int N = 8; float mn = .5*sqrt(3); void cube(float q) { for (int i=0; i<3; i++) { pushMatrix(); rotate((i+.5)*TWO_PI/3); translate(0, (-sp*2/3*mn + r)*(1-q)); fill(cols[i]); diam(); popMatrix(); } } void draw_() { background(248); pushMatrix(); translate(width/2, height/2); for (int i=-N; i<=N; i++) { for (int j=-N; j<=N; j++) { x = i*sp; y = j*mn*sp + sp*mn*2/3*t; if (j%2 != 0) x += sp*.5; tt = constrain(1.5*t - 0.001*dist(x,y,0,0) - 0.1,0,1); t1 = constrain(1.1*tt, 0, 1); t2 = constrain(1.1*tt - 0.1, 0, 1); t1 = pow(t1, .9); t2 = pow(t2, 1.1); t1 = 3*t1*t1 - 2*t1*t1*t1; t2 = .5*t2 + 1.5*t2*t2 - t2*t2*t2; pushMatrix(); translate(x, y); rotate(PI*t2); cube(t1); popMatrix(); } } popMatrix(); }