Globe.java


Below is the syntax highlighted version of Globe.java from §1.5 Input and Output.


/******************************************************************************
 *  Compilation:  javac Globe.java
 *  Execution:    java Globe N
 *  Dependencies: StdDraw.java
 *
 *  Plots a globe with angle angle.
 *
 ******************************************************************************/

public class Globe {

    public static void main(String[] args) {
        double alpha = Double.parseDouble(args[0]);
        StdDraw.setScale(-1.05, +1.05);
        StdDraw.setPenColor(StdDraw.BLUE);

        double x0 = 1, y0 = 0;
        for (double t = 0.0; t <= 20 * 360.0; t += 0.1) {
            double theta = Math.toRadians(t);
            double r = Math.cos(alpha * theta);
            double x1 = r * Math.cos(theta);
            double y1 = r * Math.sin(theta);
            StdDraw.line(x0, y0, x1, y1);
            x0 = x1;
            y0 = y1;
        }
    }

}


Copyright © 2000–2022, Robert Sedgewick and Kevin Wayne.
Last updated: Thu Aug 11 10:14:17 EDT 2022.