`~`

anderson/CAMclass/CAMClass.html
The CAM graphics class actually generates a PostScript^{13} file.
Postscript is a programming language that describes the appearance of a printed page.
It was developed by Adobe in 1985, and has become an industry standard for printing and
imaging. All major printer manufacturers make printers that can interpret PostScript.
A PostScript file is conventionally
identified via a `.ps` suffix. The schematic code listed below illustrates the
basic use of the CAM graphics class:

. . . #include <gprocess.h> // Header file for CAM graphic class . . . CAMgraphicsProcess Gprocess; // declare a graphics process CAMpostScriptDriver Pdriver("filename.ps"); // declare a PostScript driver Gprocess.attachDriver(Pdriver); // attach driver to process . . . Gprocess.frame(); // "frame" the first plot . . . Gprocess.frame(); // "frame" the second plot . . . . . . Gprocess.frame(); // "frame" the last plot Gprocess.detachDriver(); // detach the driver . . .The header file for the class is called

The program listed below uses the CAM graphics class to plot the curve for in the range to .

/* camgraph1.cpp */ /* Illustration of use of CAM graphics class to create simple line plot Program plots y = sin^2 x versus x in range -2 PI to +2 PI Program adapted from gpsmp1.cpp by Chris Anderson, UCLA 1996 */ #include <gprocess.h> #include <math.h> #include <stdlib.h> double func(double); int main() { int N_points = 400; double x_start = -2. * M_PI; double x_end = 2. * M_PI; double delta_x = (x_end - x_start) / ((double) N_points - 1.); double *x = new double[N_points]; double *y = new double[N_points]; for (int i = 0; i < N_points; i++) { x[i] = x_start + (double) i * delta_x; y[i] = func(x[i]); x[i] /= M_PI; } { // This brace used to limit scope of Gprocess CAMgraphicsProcess Gprocess; // declare a graphics process CAMpostScriptDriver Pdriver("graph1.ps"); // declare a PostScript driver Gprocess.attachDriver(Pdriver); // attach driver to process Gprocess.setAxisRange(-2., 2., -2., 2.); // set plotting ranges Gprocess.title("y = sin(x*x)"); // label the plot Gprocess.labelX("x / PI"); Gprocess.labelY("y"); Gprocess.plot(x, y, N_points); // do the plotting Gprocess.frame(); // "frame" the plot Gprocess.detachDriver(); // detach the driver } // This brace calls the destructor for Gprocess: // without it the system() call would hang up delete[] x; delete[] y; system("gv graph1.ps"); // display plot on screen return 0; } double func(double x) { return sin(x*x); }The command

`n`

values of
vector `n`

values of vector `_`

low, x`_`

high, y`_`

low, y`_`

high)`_`

label")`_`

label")

The program shown below illustrates some of the more advanced features of the CAM graphics class:

/* camgraph2.cpp */ /* Illustration of use of CAMgraphics class to create more advanced line plots Program plots three trigonometric functions versus x in range -2 PI to +2 PI using different plot styles and different line styles Program adapted from gpsmp2.cpp by Chris Anderson, UCLA 1996 */ #include <gprocess.h> #include <math.h> #include <stdlib.h> double fun1(double); double fun2(double); double fun3(double); int main() { int N_points = 100; double x_start = -2. * M_PI; double x_end = 2. * M_PI; double delta_x = (x_end - x_start) / ((double) N_points - 1.); double *x = new double[N_points]; double *y1 = new double[N_points]; double *y2 = new double[N_points]; double *y3 = new double[N_points]; for (int i = 0; i < N_points; i++) { x[i] = x_start + (double) i * delta_x; y1[i] = fun1(x[i]); y2[i] = fun2(x[i]); y3[i] = fun3(x[i]); x[i] /= M_PI; } { CAMgraphicsProcess Gprocess; // declare a graphics process CAMpostScriptDriver Pdriver("graph2.ps"); // declare a PostScript driver Gprocess.attachDriver(Pdriver); // attach driver to process /* First frame; using different plot "styles" */ Gprocess.setAxisRange(-2., 2., -2., 2.); // set plotting ranges Gprocess.title("Plots Using Different Plot Styles");// label the plot Gprocess.labelX("x / PI"); Gprocess.labelY("y"); Gprocess.plot(x, y1, N_points); // solid line (default) Gprocess.plot(x, y2, N_points, '+'); // + markers Gprocess.plot(x, y3, N_points, '+', 2); // + markers and solid line Gprocess.frame(); // "frame" the plot /* Second frame; using different plot line "styles" */ Gprocess.setAxisRange(-2., 2., -2., 2.); // set plotting ranges Gprocess.title("Plots Using Different Line Styles");// label the plot Gprocess.labelX("x / PI"); Gprocess.labelY("y"); Gprocess.plot(x, y1, N_points); // solid line (default) Gprocess.setPlotDashPattern(1); Gprocess.plot(x, y2, N_points); // dashed line Gprocess.setPlotDashPattern(4); Gprocess.plot(x, y3, N_points); // dashed-dot line Gprocess.frame(); // "frame" the plot Gprocess.detachDriver(); // detach the driver } delete[] x; delete[] y1; delete[] y2; delete[] y3; system("gv graph2.ps"); // display plots on screen return 0; } double fun1(double x) { return sin(x); } double fun2(double x) { return cos(x); } double fun3(double x) { return cos(2.*x); }The command

`n`

values of
vector `n`

values of vector
The graphs written in the first and second frames of `graph2.ps` are shown in
Figs. 2 and 3, respectively.