xxxxxxxxxx
133
class Orb {
constructor(name, mass, rad, d_sun, period, theta, col = "#ffffff") {
this.m = mass/m_scale; //mass in kg
this.r = r_scale(rad); //radius in km
this.ds = d_scale(d_sun); //d_sun in km
this.p = period;
this.theta = theta;
this.step = 3.141592653589793*2/period * dayFrame;
this.col = col
}
show() {
push();
translate(width/2, height/2);
rotate(this.theta);
stroke(this.col)
strokeWeight(this.r*2)
point(0, this.ds)
pop();
}
update() {
this.theta -= this.step;
}
}
function r_scale(x) {
return Math.pow(x, 0.43)/60
}
function d_scale(x) {
return Math.pow(x, 0.48)/232.11
}
let dayFrame = 1;
let m_scale = 1;
let sun;
let planets = [];
function setup() {
createCanvas(600, 600);
sun = new Orb("SOL",
1.989*Math.pow(10, 30),
696340,
0,
10000000,
0);
planets.push(
new Orb("MERCURY",
3.301*Math.pow(10,23),
2440,
66.313*Math.pow(10,6),
88,
293/365*TWO_PI,
"#ffffaa")
)
planets.push(
new Orb("VENUS",
4.867*Math.pow(10,24),
6052,
108.93*Math.pow(10,6),
225,
320/365*TWO_PI,
"#ff3f00"
)
)
planets.push(
new Orb("EARTH",
5.972*Math.pow(10, 24),
6371,
1.496*Math.pow(10, 8),
365.25,
0,
"#aaaaff")
)
planets.push(
new Orb("MARS",
6.42*Math.pow(10, 23),
3390,
2.331*Math.pow(10, 8),
687,
81/365*TWO_PI,
"#ff8800")
)
planets.push(
new Orb("JUPITER",
1.898*Math.pow(10, 27),
69911,
7.77*Math.pow(10, 8),
4333,
73/365*TWO_PI,
"#ffcc00")
)
planets.push(
new Orb("SATURN",
5.683*Math.pow(10, 26),
58232,
1.43*Math.pow(10, 9),
10756,
347/365*TWO_PI,
"#ffaa00")
)
planets.push(
new Orb("URANUS",
8.681*Math.pow(10, 25),
25559,
2.871*Math.pow(10, 9),
30687,
55/365*TWO_PI,
"#99ccff")
)
planets.push(
new Orb("NEPTUNE",
1.02*Math.pow(10, 26),
24622,
4.471*Math.pow(10, 9),
60190,
358/365*TWO_PI,
"#7799ff")
)
}
function draw() {
background(10);
sun.show();
for (let p of planets) {
p.show();
p.update();
}
}