xxxxxxxxxx
50
class Planet{
constructor(x, y, z, orbitRadius, direction, framesPerOrbit, radius, c,name) {
this.originPosition = createVector(x,y,z)
this.orbitR = orbitRadius
this.dir = direction
this.framesPerOrbit = framesPerOrbit
this.stepAngle = 360 / (framesPerOrbit / daysPerFrame)
this.currentAngle = -this.stepAngle
this.radius = radius
this.colour = c
this.history = []
this.position = createVector(this.orbitR/zoom,0)
this.name = name
}
update() {
angleMode(DEGREES)
let x = cos(this.currentAngle * this.dir) * this.orbitR
let y = sin(this.currentAngle * this.dir) * this.orbitR
let z = 0
this.position = createVector(this.originPosition.x + x,this.originPosition.y + y, z)
if (this.currentAngle <= 360) {
this.history.push(this.position.copy())
}
this.stepAngle = 360 / (this.framesPerOrbit / daysPerFrame)
this.currentAngle += this.stepAngle
}
show() {
noFill()
stroke(this.colour,1)
strokeWeight(1)
if (this.currentAngle < 360) {
arc(this.originPosition.x, this.originPosition.y, (this.orbitR * 2), (this.orbitR * 2),-this.currentAngle,0,OPEN,50)
} else {
ellipse(this.originPosition.x,this.originPosition.y,this.orbitR * 2,this.orbitR * 2,50)
}
noStroke()
fill(this.colour)
push()
translate(this.position.x,this.position.y)
sphere(this.radius)
pop()
}
}