Category : Modula II Source Code
Archive   : M2GRAPH.ZIP
Filename : EXAMPLE.MOD

 
Output of file : EXAMPLE.MOD contained in archive : M2GRAPH.ZIP
MODULE GraphEg2;
(* Simple plotter program for the function Sin x or Cos X
to illustrate the use of BasicGraphics
P.D. Terry, Rhodes University, 13 December 1988 *)

FROM BasicGraphics IMPORT SetWindow, PlotRealLine, DrawXAxis, DrawYAxis,
TextMode, GraphMode, PlotRealString, EraseRealLine;
FROM MathLib0 IMPORT sin, cos;
FROM EasyInOut IMPORT Prompt, Read, ReadCard, ReadReal;

CONST
MaxPoints = 200;
VAR
CH : CHAR (* read this to allow delay before halting *);
XMin, XMax : REAL (* limits of graph domain *);
Detail : CARDINAL (* points to be plotted *);
Wanted : CHAR (* specify which function required *);

PROCEDURE DrawGraph (MinX, MaxX : REAL; Function : CHAR;
Points : CARDINAL);
(* Draw Function sin/cos x for MinX <= x <= MaxX with Points samples *)
VAR
I : CARDINAL [ 0 .. MaxPoints ] (* loop control *);
X1, X2, Y1, Y2, (* general points *)
DeltaX : REAL (* scaled step size for X *);

PROCEDURE Y (X : REAL) : REAL;
(* Compute sin(X) or cos(X) *)
BEGIN
CASE Function OF
'S', 's' : RETURN sin(X)
| 'C', 'c' : RETURN cos(X)
ELSE RETURN 1.0 (* should not happen, of course *)
END
END Y (*X*);

BEGIN (*DrawGraph*)
GraphMode;
SetWindow(MinX, -1.0, MaxX, 1.0);
DrawXAxis; DrawYAxis;
PlotRealString(0.5*(MaxX-MinX), 0.5, 'Hello pat');
DeltaX := (MaxX-MinX) / FLOAT(Points) (* interval along X axis *);
X1 := MinX; Y1 := Y(X1) (* first point on curve *);
FOR I := 1 TO Points DO
X2 := MinX + FLOAT(I) * DeltaX; Y2 := Y(X2) (* next point *);
PlotRealLine(X1, Y1, X2, Y2) (*draw a line segment *);
X1 := X2; Y1 := Y2 (* ready for next line segment *)
END;
X1 := MinX; Y1 := Y(X1) (* first point on curve *);
FOR I := 1 TO Points DO
X2 := MinX + FLOAT(I) * DeltaX; Y2 := Y(X2) (* next point *);
EraseRealLine(X1, Y1, X2, Y2) (*draw a line segment *);
X1 := X2; Y1 := Y2 (* ready for next line segment *)
END
END DrawGraph;

PROCEDURE GetDetails (VAR XMin, XMax : REAL; VAR Option : CHAR;
VAR Precision : CARDINAL);
(* Prompt for, and obtain, parameters for graph drawing *)
BEGIN
Prompt('S(in or C(os graph ?');
REPEAT
Read(Option); Option := CAP(Option)
UNTIL (Option = 'C') OR (Option = 'S');
Prompt('Minimum X ? '); ReadReal(XMin);
Prompt('Maximum X ? '); ReadReal(XMax);
Prompt('How many points ? '); ReadCard(Precision)
END GetDetails;

BEGIN (*Graphics*)
GetDetails(XMin, XMax, Wanted, Detail);
DrawGraph(XMin, XMax, Wanted, Detail);
Read(CH);
Read(CH) (* delay until key pressed*);
DrawGraph(XMin, XMax, Wanted, Detail);
Read(CH);
TextMode (* return to normal mode *)
END GraphEg2.




  3 Responses to “Category : Modula II Source Code
Archive   : M2GRAPH.ZIP
Filename : EXAMPLE.MOD

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/