xxxxxxxxxx
60
class Body {
constructor(p, r, c) {
this.p = p;
this.r = r;
this.c = c;
}
update() {
this.p.add(this.s);
}
display() {
noStroke();
fill(this.c);
ellipse(this.p.x, this.p.y, this.r);
}
}
var sun;
var planets;
function setup() {
createCanvas(windowWidth, windowHeight);
sun = new Body(
createVector(width / 2, height / 2),
40,
createVector(),
color(255, 204, 0)
);
planets = [];
for (let i = 0; i < 8; i++) {
planets.push(
new Body(
createVector(
width / 2 + 80 * (pow(2, i)),
height / 2
),
10,
createVector(),
color(255, 204, 0)
)
)
}
}
function draw() {
background(31);
sun.display();
for (let i = 0; i < 8; i++) {
planets[i].update();
planets[i].display();
}
}