While the high level CCATSL graphics routines make it easy to draw the graph of a function, or to display a dataset in a standard form, it is sometimes better to take control of the graph drawing process yourself and draw each line or point individually. A sequence of commands to draw a triangle might look like:
|
Set2DPlotCL(); /* Select a 2D plot */ XRangeCL(-1.0,1.0); /* Establish the new x-scale */ YRangeCL(-1.0,1.0); /* Establish the new y-scale */ GAxesCL(); /* Draw the axes */ XYMoveCL(-1.0,-1.0); /* Move to the point (-1, -1) */ XYDrawCL( 0.0, 1.0); /* Draw a line to the point ( 0, 1) */ XYDrawCL( 1.0,-1.0); /* Draw a line to the point ( 1,-1) */ XYDrawCL(-1.0,-1.0); /* Draw a line to the point (-1,-1) */ |
XRangeCL etc. (as in the example),
but it also happens automatically when
you call one of the high level CCATSL graphics routines with an
AxisModeCT of
AUTOAXES or
RESCALE
.
Once the scales have been established, if you have not just called a high-level
graphics routine, you will probably first want to draw the
axes and axis-labels with
GAxesCL.
After that you can add points using
XYSymbolCL, lines with XYMoveCL
and XYDrawCL,
polygons with XYPolygonCL and filled
polygons with XYPolygonFillCL. The functions
XYZSymbolCL, XYZMoveCL,
XYZPolygonCL and
XYZPolygonFillCL provide similar functionality
for three-dimensional graphs.
GAxesCLSet2DPlotCL
or Set3DPlotCL prior to calling GAxesCL.
|
GAxesCL(); /* draw the axes */ |
Set2DPlotCL and Set3DPlotCL |
Set2DPlotCL(); /* prepare for a 2D plot */ /* .. */ Set3DPlotCL(); /* prepare for a 3D plot */ |
XYMoveCL, XYDrawCL, XYZMoveCL and XYZDrawCL |
XYMoveCL(1.0, 1.0) /* move the graphics cursor to (1.0, 1.0) */ XYDrawCL(1.0,-1.0) /* draw a line to (1.0, -1.0) */ |
|
XYZMoveCL(1.0, 1.0, 1.0) /* move the graphics cursor to (1.0, 1.0, 1.0) */ XYZDrawCL(1.0,-1.0, 1.0) /* draw to (1.0, -1.0, 1.0) */ |
|
/* /examples/chapter3/drawabs.c */
#include <catam.h>
int MainCL(void)
{
double x,y;
int change;
double dx,dy;
Set2DPlotCL();
XRangeCL(-300,300);
YRangeCL(-300,300);
GAxesCL();
x=0.0;
y=0.0;
XYMoveCL(0.0,0.0);
while (x*x+y*y<90000) {
change=RandomIntCL(4);
dx=0.0;
dy=0.0;
switch (change) {
case 1: dx= 1; break;
case 2: dx=-1; break;
case 3: dy= 1; break;
case 4: dy=-1; break;
}
x=x+dx;
y=y+dy;
XYDrawCL(x,y);
}
return 0;
}
|