
// Oscilloscope.java
// Robert Sedgewick and Kevin Wayne
// Slightly reformatted by Andrew Davison, Nov. 2022

// https://introcs.cs.princeton.edu/java/15inout/Oscilloscope.java.html

/* Simluate the output of an oscilloscope. Assume that the vertical and
   horizontal inputs are sinusoidal.

   These patterns are named after the French physicist, Jules A. Lissajous, 
   who studied the patterns that arise when two mutually perpendicular 
   periodic disturbances occur simultaneously.
 
    x = xAmp * sin(xVel*t + xPhase)
    y = yAmp * sin(yVel*t + yPhase)

    xAmp, yAmp = amplitudes
    xVel, yVel = angular velocity
    xPhase, yPhase = phase factors in degrees
  
   Usage:
     > compile Oscilloscope.java
     > run Oscilloscope xAmp yAmp xVel yVel xPhase yPhase
   e.g.
     > run Oscilloscope 1 1 2 3 20 45
     > run Oscilloscope 1 1 5 3 30 45 
 
*/

public class Oscilloscope
{

  public static void main(String[] args)
  {
    if (args.length != 6) {
      System.out.println("Usage: run Oscilloscope xAmp yAmp xVel yVel xPhase yPhase");
      return;
    }

    double xAmp = Double.parseDouble(args[0]); // amplitudes
    double yAmp = Double.parseDouble(args[1]);

    double xVel   = Double.parseDouble(args[2]); // angular velocities
    double yVel   = Double.parseDouble(args[3]);

    double xPhase = Math.toRadians(Double.parseDouble(args[4]));  // phases
    double yPhase = Math.toRadians(Double.parseDouble(args[5]));

    StdDraw.setXscale(-1, +1);
    StdDraw.setYscale(-1, +1);

    for (double t = 0.0; t < 10; t += 0.0001) {
      double x = xAmp * Math.sin(xVel * t + xPhase);
      double y = yAmp * Math.sin(yVel * t + yPhase);
      StdDraw.point(x, y);
    }
    System.out.println("Finished drawing");
  } /* main */

}  // end of Oscilloscope class
