home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Crawly Crypt Collection 1
/
crawlyvol1.bin
/
program
/
compiler
/
elan1v5
/
intgraph
/
tanx.e
< prev
next >
Wrap
Text File
|
1989-03-10
|
2KB
|
78 lines
PROC graphics1 (REAL CONST xmin, xmax, INT CONST steps,
REAL PROC (REAL CONST) f):
REAL VAR x, delta x :: (xmax - xmin) / real (steps - 1);
move (graphics x limit DIV 3, graphics y limit DIV 2);
put ("Computing...");
determine minimal and maximal function values;
page;
draw the axes with annotation;
draw the graphics.
determine minimal and maximal function values:
x := xmin;
REAL VAR ymin :: f (x), ymax :: f (x);
WHILE x <= xmax
REP
x INCR delta x;
IF ymax < f (x) THEN ymax := f (x)
ELIF ymin > f (x) THEN ymin := f (x)
FI
ENDREP.
draw the axes with annotation:
fix viewport and world;
draw the axis x with annotation;
draw the axis y with annotation.
fix viewport and world:
INT CONST
xvmin :: 10 * character width,
xvmax :: graphics x limit - 10 * character width,
yvmin :: graphics y limit - 2 * line height,
yvmax :: 2 * line height;
REAL VAR
sx :: real (xvmax - xvmin) / (xmax - xmin),
sy :: real (yvmax - yvmin) / (ymax - ymin),
cx :: real (xvmin) - sx * xmin,
cy :: real (yvmin) - sy * ymin.
draw the axis x with annotation:
INT CONST y0 :: round (cy);
move (xvmin, y0);
draw (xvmax, y0);
move (xvmin - 8 * character width,
y0 - line height DIV 3);
plot text (text (xmin, 7, 2));
move (xvmax - 3 * character width DIV 2,
y0 - line height DIV 3);
plot text (text (xmax, 7, 2)).
draw the axis y with annotation:
INT CONST x0 :: round (cx);
move (x0, yvmin);
draw (x0, yvmax);
move (x0 - 5 * character width,
yvmin + line height DIV 3);
plot text (text (ymin, 7, 2));
move (x0 - 5 * character width,
yvmax - 4 * line height DIV 3);
plot text (text (ymax, 7, 2)).
draw the graphics:
x := xmin;
move (round (x * sx + cx), round (f (x) * sy + cy));
WHILE x <= xmax
REP
x INCR delta x;
draw (round (x * sx + cx), round (f (x) * sy + cy))
ENDREP.
ENDPROC graphics1;
program:
enter graphics mode;
graphics1 (0.0, 6.0 * pi, 200, REAL PROC (REAL CONST) tan);
wait for confirmation (2 * graphics x limit DIV 3, 1);
leave graphics mode.
ə