Created
December 2, 2017 19:23
-
-
Save BlogBlocks/cd43ad263c161a57606782709e7c7e4d to your computer and use it in GitHub Desktop.
planer
This file contains 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
class Planet | |
{ | |
float radius; | |
float distance; | |
Planet[] planets; | |
float angle; | |
float orbitspeed; | |
Planet(float r, float d, float o) | |
{ | |
radius = r; | |
distance = d; | |
angle = random(TWO_PI); | |
orbitspeed = o; | |
//println(angle); | |
} | |
void orbit() | |
{ angle = angle + orbitspeed; | |
if (planets != null) { for (int i = 0; i < planets.length; i++) { planets[i].orbit(); } | |
} | |
} | |
void spawnMoons(int total, int level) { | |
planets = new Planet[total]; | |
for (int i = 0; i < planets.length; i++) | |
{ | |
float r = radius/(level*2); | |
float d = random(50, 150); | |
float o = random(-0.1, 0.1); | |
planets[i] = new Planet(r, d/level, o); | |
if (level < 3) { | |
int num = int(random(0,4)); | |
planets[i].spawnMoons(num, level+1); } | |
} | |
} | |
void show() | |
{ | |
pushMatrix(); | |
fill(255, 100); | |
rotate(angle); | |
translate(distance, 0); | |
ellipse(0, 0, radius*2, radius*2); | |
if (planets != null) | |
{ | |
for (int i = 0; i < planets.length; i++) | |
{ | |
planets[i].show(); | |
} | |
} | |
popMatrix(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment