float angle = 0.0; void setup() { size(500, 500); frameRate(60); smooth(); } void draw() { noFill(); noStroke(); background( 0 ); pushMatrix(); translate(width/2, height/2); //draw sun fill(255, 255, 255); ellipse(0, 0, 60, 60); //drawEllipOrbit( float baseAngle, float baseRad, float eccent, float planetRad, float orbitRotat, float planetRotate, float lineThickness ) drawEllipOrbit( angle, 170, 0.2, 50, -angle/3, true, 2 ); drawEllipOrbit( angle, 400, 0.5, 30, -angle, false, 2 ); drawEllipOrbit( angle, 200, 0.5, 10, -angle/2, false, 2 ); drawEllipOrbit( angle, 300, 0.8, 15, -angle/6, false, 2 ); //drawEllipOrbit( angle, 350, 1, 13, -angle/9, false, 2 ); drawEllipOrbit( angle, 75, 0.0, 30, angle, true, 2); popMatrix(); angle += 0.02; } void drawEllipOrbit( float baseAngle, float baseRad, float eccent, float planetRad, float orbitRotat, boolean moon, float pOrbitLineThickness ) { pushMatrix(); float a = baseRad; //the semi-major axis length float e = eccent; //ellipse eccentrity (between 0 and 1, larger number equals narrower ellipse) float b = sqrt( sq(a) * ( 1 - sq(e)) ); //the semi-minor axix length float minRad = a * e; float radius = (a * ( 1 - sq(e)))/( 1 + e * cos( angle )); //elliptical equation rotate( orbitRotat ); pushMatrix(); //noFill(); fill(122, 134, 25, 75); stroke(255, 255, 255); strokeWeight(pOrbitLineThickness); translate(0, minRad); ellipse(0, 0, b * 2, a * 2); popMatrix(); //draw outer planet noStroke(); fill(255, 255, 255); translate(0, minRad * 2); //a cheat to make sure the inner-planet moves faster closer to the sun and slower farther away rotate( baseAngle ); translate(0, radius); ellipse(0, 0, planetRad, planetRad); if (moon) { //draw inner moon's orbit path stroke(255, 255, 255); noFill(); strokeWeight(1); ellipse(0, 0, planetRad * 1.3, planetRad * 1.3); //draw inner planet's moon pushMatrix(); noStroke(); fill(255, 255, 255); rotate(angle * -3.2); translate(0, (planetRad * 1.3)/2); ellipse(0, 0, planetRad/4, planetRad/4); popMatrix(); } popMatrix(); }