home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / LANGUAGS / MODULA2 / PRINTERP.MOD < prev    next >
Text File  |  2000-06-30  |  954b  |  43 lines

  1. (* Plot the function f(x) = exp(-x) * cos(2*pi*x) on the screen in
  2.    the range x = 0 ... 4. Use 32 lines for the unit coordinate. *)
  3.  
  4. MODULE printerplot;
  5.  
  6. FROM InOut    IMPORT Write, WriteLn;
  7. FROM MathLib0 IMPORT exp, cos;
  8.  
  9. CONST xscale = 32;
  10.       yscale = 50;
  11.       yshift = 65;
  12.       twopi = 6.2831833071796;
  13.  
  14. VAR i,n: CARDINAL;
  15.     k,j: INTEGER;
  16.     x,y: REAL;
  17.  
  18. BEGIN
  19.   n := 0;
  20.   REPEAT
  21.     x := FLOAT(n)/FLOAT(xscale); i := 0;
  22.     y := exp(-x)*cos(x*twopi);
  23.     k := TRUNC((y*FLOAT(yscale))+0.5);
  24.     IF k < 0 THEN
  25.       FOR j := 0 TO yshift + k DO Write(' ') END; Write('*');
  26.       k := -k - 1;
  27.       IF k > 0 THEN
  28.         FOR j := 0 TO k DO Write(' ') END; Write('|');
  29.       END
  30.     ELSE
  31.       FOR j := 0 TO yshift DO Write(' ') END;
  32.       IF k > 0 THEN
  33.         Write('|');
  34.         DEC(k);
  35.         IF k > 0 THEN FOR j := 0 TO k DO Write(' ') END END
  36.       END;
  37.       Write('*');
  38.     END;
  39.     WriteLn;
  40.     INC(n);
  41.   UNTIL n > 96;
  42. END printerplot.
  43.