Skip to content

Instantly share code, notes, and snippets.

@volfegan
Created April 21, 2022 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save volfegan/98044f8ebba0e728fabfcfc3ca2dea59 to your computer and use it in GitHub Desktop.
Save volfegan/98044f8ebba0e728fabfcfc3ca2dea59 to your computer and use it in GitHub Desktop.
Oldschool pseudo3D floating spheres
//References:
//https://www.dwitter.net/d/11965
//https://www.dwitter.net/d/11981
float t;
void setup() {
size(1280, 720);
noStroke();
fill(0, 255, 0);
}
void draw() {
t+=.01;
clear();
for (float i=2e3; i>0; i--) {
float q=i*i;
float Q=sin(q);
float b = i%6+t;//6 spheres
//float b = i%6+t+i;//torus
float p=i+t;
float z=9+cos(b)*3+cos(p)*Q;
float s=99/z/z;//dot size
//rotating in orbit
rect(width/2*(z+sin(b)*3+sin(p)*Q)/z, height/2 + width/2 * (cos(q)-cos(b+t))/z, s, s);
//going up and towards the screen
z+=5*tan(b); //z+=5*sin(b);
s=99/z/z;//dot size
s=(s>99)?1:s;
rect(width/2*(z+sin(b)*3+sin(p)*Q)/z, height/2 + width/2 * (cos(q)-tan(b+t))/z, s, s);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment