Skip to content

Instantly share code, notes, and snippets.

@KrabCode
Created November 29, 2022 15:05
Show Gist options
  • Save KrabCode/30896683a0ff283ddeba2c97a94e1d4a to your computer and use it in GitHub Desktop.
Save KrabCode/30896683a0ff283ddeba2c97a94e1d4a to your computer and use it in GitHub Desktop.
cooler solution for equal spacing than angular diameter but I have no idea how it works...
float t = 1, x, y;
float sx, sy;
float rectSize = 30;
PMatrix3D mouseRotation = new PMatrix3D();
void setup() {
fullScreen(P3D);
rectMode(CENTER);
}
void draw() {
background(42);
// hint(DISABLE_DEPTH_TEST);
translate(width/2, height/2);
mouseRotate();
rotateX(HALF_PI);
float t = radians(frameCount)*0.1;
rotateZ(t);
drawCustomSphere();
}
void drawCustomSphere() {
int aCount = 64;
int bCount = 32;
float radius = 400;
strokeWeight(1.99);
stroke(0);
fill(255);
for (int bIndex = 0; bIndex < bCount; bIndex++) {
float bAngle = map(bIndex, 0, bCount-1, 0, PI);
float cCount = floor(aCount * cos(bAngle - HALF_PI));
for (int aIndex = 0; aIndex <= cCount; aIndex++) {
float aAngle = map(aIndex, 0, cCount-1, 0, TAU) + bAngle;
pushMatrix();
rotateZ(aAngle);
rotateX(bAngle);
translate(0, 0, radius);
rect(0, 0, rectSize, rectSize);
popMatrix();
}
}
}
void mouseRotate() {
float x = 0, y = 0;
if (mousePressed) {
x = mouseX - pmouseX;
y = mouseY - pmouseY;
}
float drag = 0.98;
float damp = 0.1;
sx = sx*drag+x*damp;
sy = sy*drag+y*damp;
float angle = 0.0025*mag(sx, sy);
PMatrix3D temp = new PMatrix3D();
temp.rotate(angle, -sy, sx, 0);
mouseRotation.preApply(temp);
applyMatrix(mouseRotation);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment