xxxxxxxxxx
114
/* I recommend to set the browser's zoom at least to 30% to view the full sketch at once: */
//Global variables:
// Array - Smaller stars:
let smallStars = [];
// Array - Bigger stars:
let mediumStars = [];
// Objects - Planets:
let mercury, venus, earth, mars, jupiter, saturn, uranus, neptune;
let rotCenterX_Sun, rotCenterY_Sun = 0;
function setup() {
createCanvas(2500, 2500);
angleMode(DEGREES);
// Create 1750 "smaller stars":
for(let i = 0; i <= 1750; i++) {
smallStars.push(new SmallStar());
}
// Create 17 "bigger stars":
for(let j = 0; j <= 35; j++) {
mediumStars.push(new MediumStar());
}
// Planets of the Solar System:
mercury = new Planet("Mercury",241, 0, 32, "#af9263");
venus = new Planet("Venus", 303.2, 0, 50, "#de6a09");
earth = new Planet("The Earth", 408.7, 0, 52, "#056f9f");
mars = new Planet("Mars", 516, 0, 36, "#b12f05");
jupiter = new Planet("Jupiter", 622, 0, 80, "#b17d5f");
saturn = new Planet("Saturn", 729, 0, 73, "#b09b43");
uranus = new Planet("Uranus", 835, 0, 50, "#46bff6");
neptune = new Planet("Neptune", 941.7, 0, 48, "#4882c8");
}
function draw() {
background(0);
// Draw the "1200" SMALLER STARS created in the initializer function:
for(let i = 0; i < smallStars.length; i++) {
smallStars[i].draw();
}
// Draw the "17" BIGGER STARS created in the initializer function:
for(let j = 0; j < mediumStars.length; j++) {
mediumStars[j].draw();
}
// We draw and set the SUN:
rotCenterX_Sun = width/2;
rotCenterY_Sun = height/2;
push();
translate(rotCenterX_Sun, rotCenterY_Sun);
strokeWeight(7);
stroke("#f65e0b");
fill("#f6c50b");
let sun = ellipse(0, 0, 350, 350);
pop();
// We draw and make orbit MERCURY:
push();
mercury.draw();
Planet.orbit(482.3);
pop();
// We draw and make orbit VENUS:
push();
venus.draw();
Planet.orbit(607.3);
pop();
// We draw and make orbit the EARTH:
push();
earth.draw();
Planet.orbit(820.3);
pop();
// We draw and make orbit MARS:
push();
mars.draw();
Planet.orbit(1033.3);
pop();
// We draw and make orbit JUPITER:
push();
jupiter.draw();
Planet.orbit(1246.3);
pop();
// We draw and make orbit SATURN:
push();
saturn.draw();
Planet.orbit(1459.3);
pop();
// We draw and make orbit URANUS:
push();
uranus.draw();
Planet.orbit(1672.3);
pop();
// We draw and make orbit NEPTUNE:
push();
neptune.draw();
Planet.orbit(1885.3);
pop();
}