Skip to content

Instantly share code, notes, and snippets.

@annahri
Created February 28, 2018 23:33
Show Gist options
  • Save annahri/e3a0e5038f5a9e4cb800a3d1e1271457 to your computer and use it in GitHub Desktop.
Save annahri/e3a0e5038f5a9e4cb800a3d1e1271457 to your computer and use it in GitHub Desktop.
Cube wave
float angle;
float w = 24;
float maxD;
int num = 16;
void setup() {
size(400, 400, P3D);
smooth(8);
maxD = dist(0, 0, num*w, num*w);
}
void draw() {
background(200);
translate(width/2, height/2 -100,-600);
scale(0.8,0.8);
rotateX(HALF_PI - radians(25));
rotateZ(radians(45));
for (int y = 0; y < num; y++) {
for (int x = 0; x < num; x++) {
pushMatrix();
float d = dist(x*w, y*w, num*w/2, num*w/2);
float offset = map(d, 0, maxD, 0, num);
float a = angle + offset;
float h = map(sin(a), -1, 1, 100, 300);
translate(x*w, y*w, 0);
box(w, w, h);
popMatrix();
}
}
angle += 0.1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment