Created
August 29, 2014 15:20
-
-
Save anonymous/16bf34ddf26cef9ecdd9 to your computer and use it in GitHub Desktop.
squares — http://tmblr.co/ZOLwww1PVRyti
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
| 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 = 16; | |
| int numFrames = 108; | |
| float shutterAngle = .6; | |
| boolean recording = true; | |
| void setup_() { | |
| size(500, 500); | |
| // smooth(8); | |
| rectMode(CENTER); | |
| noStroke(); | |
| } | |
| float ease(float q) { | |
| return 3*q*q - 2*q*q*q; | |
| } | |
| float l = 30, lf; | |
| int N = 10; | |
| float x, y; | |
| float th, tt; | |
| color c1 = color(40), c2 = color(248); | |
| void draw_() { | |
| pushMatrix(); | |
| translate(width/2, height/2); | |
| scale(pow(2, .5*t)); | |
| rotate(QUARTER_PI*t); | |
| background(c1); | |
| for (int i=-N; i<=N; i++) { | |
| for (int j=-N; j<=N; j++) { | |
| x = i*l; | |
| y = j*l; | |
| tt = constrain(3*(t-.0025*dist(x, y, 0, 0)), 0, 1); | |
| th = QUARTER_PI*ease(tt); | |
| lf = 1/(sin(th)+cos(th)); | |
| pushMatrix(); | |
| translate(x, y); | |
| fill(c1); | |
| rect(0, 0, l, l); | |
| fill(c2); | |
| if ((i+j)%2 != 0){ | |
| scale(tt); | |
| rotate(th); | |
| } | |
| else | |
| rotate(-th); | |
| rect(0, 0, l*lf, l*lf); | |
| popMatrix(); | |
| } | |
| } | |
| popMatrix(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment