Created
August 6, 2014 20:36
-
-
Save anonymous/e1cca28164956b7ca4bf to your computer and use it in GitHub Desktop.
twisting cubes — http://tmblr.co/ZOLwww1NYf3pf
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 characters
| // code by dave whyte >:) | |
| // beesandbombs.tumblr.com | |
| 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 = false; | |
| void setup_() { | |
| size(500, 500, P3D); | |
| smooth(8); | |
| strokeWeight(1.5); | |
| stroke(32); | |
| fill(250); | |
| } | |
| float l =110; | |
| int N = 8; | |
| float dd; | |
| float tt; | |
| void draw_() { | |
| background(32); | |
| pushMatrix(); | |
| translate(width/2, height/2, -1000); | |
| rotateX(-atan(sqrt(.5))); | |
| rotateY(QUARTER_PI); | |
| for (int i=-N; i<=N; i++) { | |
| for (int j=-N; j<=N; j++) { | |
| pushMatrix(); | |
| translate(i*l, j*l, (i+j)*l); | |
| dd = dist(i, j, i+j, 0, 0, 0); | |
| tt = constrain(1.7*t - 0.1*dd,0,1); | |
| tt = min(1,1.4*tt); | |
| for (int _=0; _<2; _++) | |
| tt = 3*tt*tt - 2*tt*tt*tt; | |
| rotateY(-HALF_PI*tt); | |
| box(l-1); | |
| popMatrix(); | |
| } | |
| } | |
| popMatrix(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment