
// Globe.java
// Robert Sedgewick and Kevin Wayne
// Slightly reformatted by Andrew Davison, Nov. 2022

// https://introcs.cs.princeton.edu/java/15inout/Globe.java.html

/* Plots a series of rotated circles
   using the polar coordinates (r, theta) of the
   function f(theta) = cos(alpha × theta) for theta ranging from 0 to 7200 degrees.

   Usage:
     java Globe 0.8
     java Globe 0.9
     java Globe 0.95
*/

public class Globe
{

  public static void main(String[] args)
  {
    if (args.length != 1) {
      System.out.println("Usage: java Globe <alpha; e.g. 0.9>");
      System.exit(1);
    }
    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;
    }
  } /* main */


}  // end of Globe class
