home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / modula2 / library / modula1 / pplot.mod < prev    next >
Text File  |  1987-06-11  |  2KB  |  68 lines

  1. MODULE printerplot;
  2.  
  3. FROM InOut    IMPORT Write, WriteLn;
  4. FROM Terminal IMPORT WriteString;
  5. FROM MathLib0 IMPORT exp, cos;
  6.  
  7. CONST xscale = 32;
  8.       yscale = 50;
  9.       yshift = 65;
  10.       twopi = 6.2831833071796;
  11.  
  12. TYPE Double = RECORD
  13.                 CASE BOOLEAN OF
  14.                   TRUE: r:REAL|
  15.                   FALSE: h,l:CARDINAL
  16.                 END
  17.               END;
  18.  
  19. VAR i,n: CARDINAL;
  20.     k,j: INTEGER;
  21.     x,y: REAL;
  22.  
  23. PROCEDURE WriteBits(x: REAL);
  24. VAR high,low: BITSET;
  25.     i: CARDINAL;
  26.     w: Double;
  27.  
  28. BEGIN
  29.   w.r := x;
  30.   high := BITSET(w.h);
  31.   FOR i := 0 TO 15 DO
  32.     IF i IN high THEN Write('1') ELSE Write('0') END
  33.   END;
  34.   low := BITSET(w.l);
  35.   FOR i := 0 TO 15 DO
  36.     IF i IN low THEN Write('1') ELSE Write('0') END
  37.   END
  38. END WriteBits;
  39.  
  40. BEGIN
  41.   n := 0;
  42.   REPEAT
  43.     x := FLOAT(n)/FLOAT(xscale); i := 0;
  44. WriteString('x = '); WriteBits(x); WriteLn;
  45.     y := exp(-x)*cos(x*twopi);
  46. WriteString('y = '); WriteBits(y); WriteLn;
  47.     k := TRUNC((y*FLOAT(yscale))+0.5);
  48. WriteString('k = '); WriteBits(k); WriteLn;
  49.     IF k < 0 THEN
  50.       FOR j := 0 TO yshift + k DO Write(' ') END; Write('*');
  51.       k := -k - 1;
  52.       IF k > 0 THEN
  53.         FOR j := 0 TO k DO Write(' ') END; Write('|');
  54.       END
  55.     ELSE
  56.       FOR j := 0 TO yshift DO Write(' ') END;
  57.       IF k > 0 THEN
  58.         Write('|');
  59.         DEC(k);
  60.         IF k > 0 THEN FOR j := 0 TO k DO Write(' ') END END
  61.       END;
  62.       Write('*');
  63.     END;
  64.     WriteLn;
  65.     INC(n);
  66.   UNTIL n > 96;
  67. END printerplot.
  68.