/* Solar System Program Animates a solar system with one sun, two planets, where each planet has a moon. */ void setup() { size(400,400); ellipseMode(CENTER); background(100); } int earth_angle = 20; // angle of earth around sun int moon_angle = 20; // angle of moon around the earth void draw() { myBackground(); translate(width/2,height/2); sun(); // Draw the first planet and moon pushMatrix(); rotate(radians(earth_angle)); translate(120,0); earth(); rotate(radians(moon_angle)); translate(50,0); moon(); popMatrix(); // Draw the second planet and moon rotate(radians(.5*earth_angle+180)); translate(150,0); earth(); rotate(radians(2*moon_angle+45)); translate(30,0); moon(); moon_angle += 2; earth_angle += 1; } void sun() { fill(255,255,0); ellipse(0,0,100,100); } void earth() { fill(0,0,255); ellipse(0,0,30,30); } void moon() { fill(255); ellipse(0,0,10,10); } // creates the star background. void myBackground() { randomSeed(0); background(0); stroke(255); for (int i=0; i < 1000; i++) { point(random(width), random(height)); } stroke(0); }