Globe.java


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


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

import java.awt.Color;

public class Globe { 

    public static void main(String[] args) { 
        double alpha = Double.parseDouble(args[0]);
        int SIZE = 128;
        StdDraw.create(SIZE, SIZE);
        StdDraw.setScale(-1, -1, 1, 1);
        StdDraw.setColor(Color.blue);

        for (double theta = 0.0; theta <= 20 * 360.0; theta += 0.1) {

            double r = Math.cos(alpha * Math.toRadians(theta));

            // fly to center
            StdDraw.go(0, 0);

            // set angle to theta
            StdDraw.rotate(theta);
            StdDraw.goForward(r);
            StdDraw.spot();
            StdDraw.rotate(-theta);
        }

        StdDraw.show();
    }

}


Last updated: Sun Oct 24 22:26:04 EDT 2004 .
Copyright © 2004, Robert Sedgewick and Kevin Wayne.