Skip to content

Instantly share code, notes, and snippets.

@patricoferris
Created August 11, 2018 09:36
Show Gist options
  • Save patricoferris/69b69f68ed7a5248adbfa8b90a5b7809 to your computer and use it in GitHub Desktop.
Save patricoferris/69b69f68ed7a5248adbfa8b90a5b7809 to your computer and use it in GitHub Desktop.
//Our global variables
let earth;
let moon;
let r = 225;
function setup() {
createCanvas(640, 640);
//Creating our Earth and Moon
earth = new Planet(createVector(width/2, height/2), 1000, 100, 'blue');
//Notice we're starting the moon directly 'east' to our Earth, so the initial velocity is straight upwards.
//Feel free to experiment with this initial velocity to see how it affects the orbit
moon = new Satellite(createVector(width/2 + r, height/2), 10, 50, 'white', createVector(0, -4));
}
function draw() {
//Clear the canvas
background(0);
//Draw the Earth
earth.show();
//If the Moon is close enough to the Earth, apply the force
if(getDistance(earth, moon) <= r) {
moon.applyForce(centripetalForce(moon, earth.position));
}
//Update the moon
moon.update();
//Render it to the canvas... and then loop back to the start
moon.show();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment