Skip to content

Instantly share code, notes, and snippets.

@KOWLOR
Created February 4, 2019 16:57
Show Gist options
  • Save KOWLOR/c09c36f6788bcebfb3834a487130373b to your computer and use it in GitHub Desktop.
Save KOWLOR/c09c36f6788bcebfb3834a487130373b to your computer and use it in GitHub Desktop.
trippy dots
void setup() {
size(720, 720, P3D);
smooth(8);
noStroke();
fill(200);
ortho(-width/2, width/2, -height/2, height/2, -width/2, 3*width);
}
int N = 16, n = 5, l = 50, r = 2; //"n" is side length of the inner cube
float t, ang = PI/100;
void draw() {
t = mouseX*1.0/width;
background(30);
push();
translate(width/2, height/2);
rotateY(sin(TWO_PI*t)*ang);
rotateX((cos(TWO_PI*t)-1)*ang);
for (int a = 0; a < 3; a++) {
push();
rotate(TWO_PI/3*a);
rotateX(-atan(1/sqrt(2)));
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
push();
if (i + 1 > n || j + 1 > n) {
rotateY(-PI/4);
translate(i*l, -j*l);
sphere(r);
} else {
rotateY(PI/4);
translate(i*l - (n - 1)*l, -j*l, (n - 1)*l);
sphere(r);
}
pop();
}
}
pop();
}
pop();
}
void push() {
pushMatrix();
pushStyle();
}
void pop() {
popStyle();
popMatrix();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment