xxxxxxxxxx
91
let mercury = {
color: "#D5D2D1",
distance: 50,
diameter: 8,
angle: 30,
},
venus = {
color: "#8B7D82",
distance: 75,
diameter: 10,
angle: 1,
},
earth = {
color: "#4F42B5",
distance: 100,
diameter: 9,
angle: 2,
},
mars = {
color: "#c1440e",
distance: 125,
diameter: 8,
angle: 3,
},
jupiter = {
color: "#D39C7E",
distance: 160,
diameter: 25,
angle: 2,
},
saturn = {
color: "#C3A171",
distance: 210,
diameter: 20,
angle: 1,
},
uranus = {
color: "#BBE1E4",
distance: 250,
diameter: 15,
angle: 3,
},
neptune = {
color: "#4b70dd ",
distance: 280,
diameter: 10,
angle: 1,
};
function setup() {
createCanvas(window.innerWidth, window.innerHeight)
}
function draw() {
background("black")
translate(width/2, height/2)
drawSun()
drawPlanet(mercury);
drawPlanet(venus);
drawPlanet(earth);
drawPlanet(mars);
drawPlanet(jupiter);
drawPlanet(saturn);
drawPlanet(uranus);
drawPlanet(neptune);
}
function drawSun() {
fill("yellow");
noStroke();
circle(0, 0, 50);
}
function drawPlanet(planet) {
fill(planet.color);
stroke(planet.color);
circle(
planet.distance * cos(planet.angle),
planet.distance * sin(planet.angle),
planet.diameter
);
noFill()
stroke(planet.color)
// Drawing orbit
circle(0,0,2*planet.distance);
updatePlanet(planet);
}
function updatePlanet(planet) {
planet.angle = planet.angle + (1 / planet.distance);
}