/************************************************************************* * Compilation: javac EarthSimple.java * Execution: java EarthSimple * Dependencies: StdDraw.java * * Skeleton code for the solris system. * * % java EarthSimple * *************************************************************************/ public class EarthSimple { public static void main(String[] args) { // set the scale of the coordinate system StdDraw.setXscale(-1.0, 1.0); StdDraw.setYscale(-1.0, 1.0); // initial values double earthAngle = 0; // main animation loop while (true) { // clear the background StdDraw.setPenColor(StdDraw.BLACK); StdDraw.filledSquare(0, 0, 2); // compute the location of the Earth double earthX = 0.75 * Math.cos(earthAngle); double earthY = 0.75 * Math.sin(earthAngle) * 0.25; earthAngle += 2*Math.PI/365; earthAngle = earthAngle % (2 * Math.PI); // // You need to add codes to the following code // to include the Moon // if (earthAngle < Math.PI) { // the Earth is behind the Sun StdDraw.setPenColor(StdDraw.BLUE); // draw the Earth StdDraw.filledCircle(earthX, earthY, 0.15); StdDraw.setPenColor(StdDraw.RED); // draw the Sun StdDraw.filledCircle(0, 0, 0.3); } else { // the Earth is in front of the Sun StdDraw.setPenColor(StdDraw.RED); // draw the Sun StdDraw.filledCircle(0, 0, 0.3); StdDraw.setPenColor(StdDraw.BLUE); // draw the Earth StdDraw.filledCircle(earthX, earthY, 0.15); } // delay for one day (for us 10ms) StdDraw.show(10); } } }