home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / ddjmag / ddj8804.arc / PORTER.ARC / PORTER.LS4 < prev    next >
Text File  |  1980-01-01  |  2KB  |  57 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6. MODULE MathPlot;
  7.  
  8. (* Graphs the function y = cos x + sin 2x using LineDwg *)
  9. (* K. Porter, DDJ, April 88                             *)
  10.  
  11. FROM MathLib0 IMPORT sin, cos, real, entier;
  12. FROM LineDwg IMPORT line, dot, clear, WriteString, Px, Py;
  13. FROM InOut IMPORT Read;
  14. FROM SYSTEM IMPORT REGISTERS, INT;
  15.  
  16. VAR  x, sx, cx, y : REAL;
  17.      xc           : INTEGER;
  18.      ch           : CHAR;
  19.      reg          : REGISTERS;
  20.  
  21. PROCEDURE yc (y : REAL) : INTEGER;
  22. BEGIN
  23.   RETURN entier (y * 100.0) + 300;
  24. END yc;
  25.  
  26. BEGIN
  27.   clear;
  28.   Px :=   0; Py := 300; line (0, 800);        (* x axis *)
  29.   Px :=   0; Py := yc (1.0);                   (* grids *)
  30.   WriteString ("  1"); 
  31.   dot (2, Px, Py);                     (* set dark gray *)
  32.   line (0, 750);
  33.   Px := 0; Py := yc (-1.0);
  34.   WriteString (" -1"); line (0, 750);
  35.   FOR xc := 125 TO 799 BY 126 DO      (* vertical grids *)
  36.     Px := xc; Py := yc (2.0); line (6, 400);
  37.   END;  
  38.   Px := 310; Py := 599;
  39.   WriteString ("y = cos x + sin 2x ");  
  40.  
  41.   FOR xc := 1 TO 799 DO
  42.     x  := real (xc) / 80.0;             (* x to radians *)
  43.     sx := sin (2.0 * x);
  44.     dot (2, xc, yc (sx));     (* plot sine in dark gray *)
  45.     cx := cos (x);
  46.     dot (1, xc, yc (cx));          (* cos in light gray *)
  47.     y  := sx + cx;
  48.     dot (0, xc, yc (y));      (* plot function in white *)
  49.   END;
  50.   Read (ch);  
  51.   reg.AH := 0; reg.AL := 3; INT (16, reg)  (* text mode *)  
  52. END MathPlot.
  53.   
  54.  
  55. -30-
  56.  
  57.