Code viewer for World: Solar System Generator (cl...

// Cloned by Martin Derwin on 27 Sep 2022 from World "Solar System Generator" by Mathias Bazin 
// Please leave this clone trail here.
 
// port of Daniel Shiffman's pde SolarSystemGenerator by madacoo
AB.drawRunControls = false;

function setup() {
    createCanvas(600, 600);
    sun = new Planet(50, 0, 0, random(TWO_PI));
    sun.spawnMoons(5, 1);
}

function draw() {
    background(51);
    translate(width/2, height/2);
    sun.show();
    sun.orbit();
}

class Planet {
    constructor(radius, distance, orbitspeed, angle) {
        this.radius = radius;
        this.distance = distance;
        this.orbitspeed = orbitspeed;
        this.angle = angle;
        this.planets = [];
    }


    orbit() {
        this.angle += this.orbitspeed;
        for (let i in this.planets) {
            this.planets[i].orbit();
        }
    }


    spawnMoons(total, level) {
        for (let i = 0; i < total; i++) {
            let r = this.radius/(level*2);
            let d = random(50, 150);
            let o = random(-0.1, 0.1);
            let a = random(TWO_PI);
            this.planets.push(new Planet(r, d/level, o, a));
            if (level < 3) {
                let num = Math.floor(random(0, 4));
                this.planets[i].spawnMoons(num, level+1);
            }
        }
    }


    show() {
        push();
        
        for (let i = 0; i < 8; i++)
        {
            let r = random(255); // r is a random number between 0 - 255
            let g = random(100,200); // g is a random number betwen 100 - 200
            let b = random(100); // b is a random number between 0 - 100
            let a = random(200,255); // a is a random number between 200 - 255
            
            noStroke();
            fill(r, 0, 0, a);
            
            rotate(this.angle);
            translate(this.distance, 0);
            ellipse(0, 0, this.radius*2);
            for (let i in this.planets) {
                for (let j = 0; j < 10; j++)
                {
                    this.planets[i].show();   
                }
            }
        }
        pop();
    }

}