Created
August 10, 2018 22:12
-
-
Save patricoferris/a8f38187051d31f5fe46037a9b7994b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Satellite extends Planet { | |
constructor(position, mass, radius, color, vel) { | |
//Telling Planet to build a base planet for us | |
super(position, mass, radius, color); | |
//Redefining the velocity to be something we pass it (shadowing) | |
this.velocity = vel; | |
//Our new variable acceleration | |
this.acceleration = createVector(0, 0); | |
} | |
//An apply force function - check the physics section to understand this | |
applyForce(force) { | |
var f = p5.Vector.div(force, this.mass); | |
this.acceleration.add(f); | |
} | |
//And an update function | |
update() { | |
this.velocity.add(this.acceleration) | |
this.position.add(this.velocity); | |
this.acceleration.mult(0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment