Oscilloscope.java
Below is the syntax highlighted version of Oscilloscope.java
from §2.4 Input and Output.
/*************************************************************************
* Compilation: javac Oscilloscope.java
* Execution: java Oscilloscope A B wX wY phiX phiY
* Dependencies: StdDraw.java
*
* Simluate the output of an oscilloscope. Assume that the vertical and
* horizontal inputs are sinusoidal.
*
* x = A sin (wX + phiX)
* y = B sin (wY + phiY)
*
* % java Oscilloscope 1 1 2 3 30 45
*
*************************************************************************/
public class Oscilloscope {
public static void main(String args[]) {
int SIZE = 600;
StdDraw.create(SIZE, SIZE);
StdDraw.setScale(-1, -1, 1, 1);
double A = Double.parseDouble(args[0]); // amplitudes
double B = Double.parseDouble(args[1]);
double wX = Double.parseDouble(args[2]); // angular frequencies
double wY = Double.parseDouble(args[3]);
double phiX = Double.parseDouble(args[4]); // phase factors
double phiY = Double.parseDouble(args[5]);
phiY = phiY * Math.PI / 180.0; // convert to radians
phiY = phiY * Math.PI / 180.0; // convert to radians
for (double t = 0.0; t < 10; t += 0.0001) {
double x = A * Math.sin(wX * t + phiX);
double y = B * Math.sin(wY * t + phiY);
StdDraw.go(x, y);
StdDraw.spot();
StdDraw.pause(10);
}
}
}
Last updated: Sun Oct 24 22:26:04 EDT 2004
.
Copyright © 2004, Robert Sedgewick and Kevin Wayne.