Elliptical Orbit
in
Programming Questions
•
1 year ago
I'm trying to make a small solar system. I've made some planets and moons that are on a circular rotational orbit using translate() and rotate(). I'm looking to add a small comet that moves along an ellipitical orbit. I know that rotate won't work for this, but I'm not sure where to go from there.
- float SunDiam = 80;
- float VenusDiam = 24;
- float VenusOrbitRadius = 120;
- float VenusAngle = 0;
- float EarthDiam = 30;
- float EarthOrbitRadius = 200;
- float EarthAngle = 0;
- float MoonDiam = 6;
- float MoonOrbitRadius = 26;
- float MoonAngle = 0;
- void setup() {
- size(1024,768);
- frameRate(30);
- }
- void draw() {
- background(0,0,0); // inky blackness of space
- translate(width/2,height/2); // move origin to the center of the screen
- noStroke();
- fill(255,200,64); // yellow-orange
- ellipse(0,0,SunDiam,SunDiam); // the mighty Sun
- // save the solar system
- pushMatrix();
- // rotate Venus around the sun
- rotate(VenusAngle);
- // move out to Venus orbit
- translate(VenusOrbitRadius,0);
- fill(155,135,95);
- ellipse(0,0,VenusDiam,VenusDiam);
- // return to the sun
- popMatrix();
- // rotate around the sun
- rotate(EarthAngle);
- // move out to Earth orbit
- translate(EarthOrbitRadius, 0);
- fill(64,64,255); // blue-ish
- ellipse(0,0,EarthDiam,EarthDiam); // the noble Earth
- // rotate around the Earth
- rotate(MoonAngle);
- // hove out to Moon orbit
- translate(MoonOrbitRadius,0);
- fill(192,192,180); //grayish
- ellipse(0,0,MoonDiam,MoonDiam); // the friendly Moon
- VenusAngle += 0.008;
- EarthAngle += 0.005;
- MoonAngle += 0.02;
- }
1