Created
July 11, 2017 22:48
-
-
Save beesandbombs/d88cd1f969dd0be198e9afd133af23d2 to your computer and use it in GitHub Desktop.
chequered waves
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("d###.gif"); | |
if (frameCount==numFrames) | |
exit(); | |
} | |
} | |
////////////////////////////////////////////////////////////////////////////// | |
int samplesPerFrame = 4; | |
int numFrames = 240; | |
float shutterAngle = .5; | |
boolean recording = false; | |
void setup() { | |
size(800, 600, P3D); | |
result = new int[width*height][3]; | |
rectMode(CENTER); | |
fill(32); | |
noStroke(); | |
} | |
float d_; | |
void vert(float x_, float y_){ | |
d_ = sq(x_)+sq(y_); | |
vertex(x_,y_,110*sin(TWO_PI*t - .000058*d_)*exp(-.000022*d_)); | |
} | |
void element(float x1, float y1, float x2, float y2) { | |
vert(x1, y1); | |
vert(x2, y1); | |
vert(x2, y2); | |
vert(x2, y2); | |
vert(x1, y2); | |
vert(x1, y1); | |
} | |
void patch(float x1, float y1, float x2, float y2) { | |
for (int i=0; i<N; i++) | |
for (int j=0; j<N; j++) | |
element(map(i, 0, N, x1, x2), map(j, 0, N, y1, y2), | |
map(i+1, 0, N, x1, x2), map(j+1, 0, N, y1, y2)); | |
} | |
int N = 8; | |
float l = 40; | |
void draw_() { | |
background(250); | |
push(); | |
translate(width/2, height/2 - 50); | |
rotateX(.75); | |
rotate(QUARTER_PI + HALF_PI*t); | |
fill(32); | |
noStroke(); | |
beginShape(TRIANGLES); | |
for (int i=-4; i<5; i++) | |
for (int j=-4; j<5; j++) | |
if ((i+j)%2 == 0) | |
patch(l*(i-.5), l*(j-.5), l*(i+.5), l*(j+.5)); | |
endShape(); | |
push(); | |
fill(32,140,220); | |
scale(1,1,-1); | |
beginShape(TRIANGLES); | |
for (int i=-4; i<5; i++) | |
for (int j=-4; j<5; j++) | |
if ((i+j)%2 != 0) | |
patch(l*(i-.5), l*(j-.5), l*(i+.5), l*(j+.5)); | |
endShape(); | |
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/884763049101537280