/************************************************************************* * Compilation: javac Second.java * Execution: java Second initial_second * Dependencies: StdDraw.java * * Skeleton code for the clock. * * % java Second 15 * *************************************************************************/ public class Second { 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 second of the clock from the input int second = Integer.parseInt(args[0]); // initial angle for the second hand double secondAngle = -second * Math.PI/30 + Math.PI / 2.0; // draw the panel StdDraw.circle(0, 0, 1); // // Place your code here for drawing the markers and digits on the panel // // main animation loop while (true) { // clear the background StdDraw.setPenColor(StdDraw.WHITE); StdDraw.filledCircle(0, 0, 0.8); double x, y; // // PLACE your code here for the hour hand and minute hand // // compute the location of the second hand x = 0.75 * Math.cos(secondAngle); y = 0.75 * Math.sin(secondAngle); // draw the second hand on the canvas StdDraw.setPenColor(StdDraw.BLACK); StdDraw.setPenRadius(0.005); StdDraw.line(0, 0, x, y); //update the second hand angle secondAngle -= Math.PI/30; secondAngle = secondAngle % (2 * Math.PI); // display and pause for 1 s StdDraw.show(1000); } } }