Last active
July 3, 2019 00:01
-
-
Save KrabCode/d9de9d421870d0859790896097a84b63 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public void setup() { | |
size(800, 800, P3D); | |
smooth(8); | |
} | |
public void draw() { | |
float t = radians(frameCount*.2f); | |
background(0); | |
translate(width*.5f, height*.5f); | |
rotateX(t*.5); | |
rotateY(t*.25); | |
rotateZ(t); | |
float r = 250; | |
float rectSize = 20; | |
float rowAngularDiameter = angularDiameter(r, rectSize); | |
int rowCount = floor(PI/rowAngularDiameter); | |
for (int i = 0; i < rowCount; i++) { | |
//go from north pole to south pole | |
float rowAngle = map(i, 0, rowCount-1, -HALF_PI, HALF_PI); | |
float rowRadius = r*cos(rowAngle); | |
float columnAngularStep = angularDiameter(rowRadius, rectSize); | |
int columnCount = max(1, floor(TWO_PI/columnAngularStep)); //at least 1 column should be shown at poles | |
for (int j = 0; j < columnCount; j++) { | |
//go all the way around the sphere | |
float columnAngle = map(j, 0, columnCount, 0, TWO_PI); | |
pushMatrix(); | |
rotateY(columnAngle); | |
rotateZ(rowAngle); | |
float elevation = .2f*r*noise(5+5*cos(columnAngle), 5+5*cos(rowAngle*2), t); | |
translate(r+elevation, 0, 0); | |
rotateY(HALF_PI); | |
rectMode(CENTER); | |
stroke(255); | |
strokeWeight(1); | |
fill(0); | |
rect(0, 0, rectSize, rectSize); | |
popMatrix(); | |
} | |
} | |
} | |
float angularDiameter(float r, float size) { | |
return atan(2*(size/(2*r))); | |
} |
Author
KrabCode
commented
Jul 1, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment