Created
July 12, 2017 18:39
-
-
Save beesandbombs/d6d0549429b2e48db844f38d0e19a893 to your computer and use it in GitHub Desktop.
spring cube
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 = 200; | |
float shutterAngle = .6; | |
boolean recording = false; | |
void setup() { | |
size(750, 600, P3D); | |
smooth(8); | |
result = new int[width*height][3]; | |
colorMode(HSB,1); | |
noFill(); | |
ortho(); | |
} | |
float x, y, z, tt; | |
int N = 90; | |
float q; | |
float h = 350, ph, r, R = 24; | |
float lof, xof, yof; | |
void helix(float th, float of) { | |
beginShape(); | |
for (int i=0; i<N; i++) { | |
q = i/float(N-1); | |
ph = 12*TWO_PI*q - 3*TWO_PI*t; | |
r = map(cos(TWO_PI*q), 1, -1, 0, R); | |
lof = map(cos(TWO_PI*q), 1, -1, 0, of); | |
xof = lof*cos(th); | |
yof = lof*sin(th); | |
y = lerp(-h/2, h/2, q); | |
curveVertex(r*cos(ph) + xof, y, r*sin(ph) + yof); | |
} | |
endShape(); | |
} | |
boolean black; | |
void things(){ | |
push(); | |
rotateX(-ia); | |
rotateY(PI/3); | |
for (int i=-n; i<n; i++) { | |
for (int j=-n; j<n; j++) { | |
randomSeed(2345*i+3456789*j); | |
tt = (t + 100 - 0.2*dist(i+.5,j+.5,0,0)); | |
stroke((.16*(i+j*.5)+100.75)%1,.8,1); | |
if(black) | |
stroke(.1); | |
push(); | |
translate((i+.5)*sep,0,(j+.5)*sep); | |
helix(TWO_PI*t, 18); | |
pop(); | |
} | |
} | |
pop(); | |
} | |
int n = 2; | |
float sep = 84; | |
void draw_() { | |
background(.1); | |
push(); | |
translate(width/2, height/2); | |
push(); | |
strokeWeight(2.5); | |
black = false; | |
things(); | |
pop(); | |
push(); | |
black = true; | |
strokeWeight(8); | |
translate(0,0,-5); | |
things(); | |
pop(); | |
pop(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
gif: https://twitter.com/beesandbombs/status/885207069829332992