Created
September 14, 2017 17:54
-
-
Save beesandbombs/d01e9a4bf8c8d17165be6060f86d0c48 to your computer and use it in GitHub Desktop.
two squares / four triangles
This file contains 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, c; | |
float ease(float p) { | |
return 3*p*p - 2*p*p*p; | |
} | |
float ease(float p, float g) { | |
if (p < 0.5) | |
return 0.5 * pow(2*p, g); | |
else | |
return 1 - 0.5 * pow(2*(1 - p), g); | |
} | |
float mn = .5*sqrt(3), ia = atan(sqrt(.5)); | |
void push() { | |
pushMatrix(); | |
pushStyle(); | |
} | |
void pop(){ | |
popStyle(); | |
popMatrix(); | |
} | |
void draw() { | |
if(!recording){ | |
t = mouseX*1.0/width; | |
c = mouseY*1.0/height; | |
if(mousePressed) | |
println(c); | |
draw_(); | |
} | |
else { | |
for (int i=0; i<width*height; i++) | |
for (int a=0; a<3; a++) | |
result[i][a] = 0; | |
c = 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 = 4; | |
int numFrames = 280; | |
float shutterAngle = .6; | |
boolean recording = false; | |
void setup() { | |
size(800,800,P3D); | |
smooth(8); | |
pixelDensity(recording ? 1 : 2); | |
result = new int[width*height][3]; | |
blendMode(EXCLUSION); | |
fill(255); | |
noStroke(); | |
} | |
float l = 320; | |
float t1, t2; | |
void tri(){ | |
triangle(-l/2,0,l/2,0,0,-l/2); | |
} | |
void thing1(){ | |
push(); | |
scale(pow(2,.5-.5*t1)); | |
push(); | |
rotate(-QUARTER_PI*t1); | |
push(); | |
translate(0,-l/2*t1); | |
tri(); | |
pop(); | |
push(); | |
rotate(PI); | |
translate(0,-l/2*t1); | |
tri(); | |
pop(); | |
pop(); | |
pop(); | |
} | |
void thing2(){ | |
push(); | |
rotate(QUARTER_PI); | |
push(); | |
translate(0,-l/2*t2); | |
tri(); | |
pop(); | |
push(); | |
rotate(PI); | |
translate(0,-l/2*t2); | |
tri(); | |
pop(); | |
pop(); | |
} | |
void draw_() { | |
t1 = ease(constrain(map(t,.125,.475,0,1),0,1),4.5); | |
t2 = ease(constrain(map(t,.525,.875,0,1),0,1),5.5); | |
background(0); | |
push(); | |
translate(width/2, height/2); | |
scale(-1,1); | |
rotate(QUARTER_PI-QUARTER_PI*t); | |
scale(pow(sqrt(2),-t)); | |
thing1(); | |
thing2(); | |
pop(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment