home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / elan / intgraph / lissa.eln next >
Text File  |  1988-10-13  |  3KB  |  94 lines

  1.  
  2. PROC graphics2 (REAL CONST tmin, tmax, INT CONST steps,
  3.                 REAL PROC (REAL CONST) fx, fy):
  4.    REAL VAR t, delta t :: (tmax - tmin) / real (steps - 1);
  5.    move (graphics x limit DIV 3, graphics y limit DIV 2);
  6.    put ("Computing...");
  7.    determine minimal and maximal function values;
  8.    page;
  9.    draw the axes with annotation;
  10.    draw the graphics.
  11.  
  12. determine minimal and maximal function values:
  13.    t := tmin;
  14.    REAL VAR xmin :: fx (t), xmax :: fx (t),
  15.             ymin :: fy (t), ymax :: fy (t);
  16.    WHILE t <= tmax
  17.    REP
  18.      t INCR delta t;
  19.      IF xmax < fx (t) THEN xmax := fx (t)
  20.      ELIF xmin > fx (t) THEN xmin := fx (t)
  21.      FI;
  22.      IF ymax < fy (t) THEN ymax := fy (t)
  23.      ELIF ymin > fy (t) THEN ymin := fy (t)
  24.      FI
  25.    ENDREP.
  26.  
  27. draw the axes with annotation:
  28.    fix viewport and world;
  29.    draw the axis x with annotation;
  30.    draw the axis y with annotation.
  31.  
  32. fix viewport and world:
  33.    INT CONST
  34.       xvmin :: 10 * character width,
  35.       xvmax :: graphics x limit - 10 * character width,
  36.       yvmin :: graphics y limit - 2 * line height,
  37.       yvmax :: 2 * line height;
  38.    REAL VAR
  39.       sx :: real (xvmax - xvmin) / (xmax - xmin),
  40.       sy :: real (yvmax - yvmin) / (ymax - ymin),
  41.       cx :: real (xvmin) - sx * xmin,
  42.       cy :: real (yvmin) - sy * ymin.
  43.  
  44. draw the axis x with annotation:
  45.    INT CONST y0 :: round (cy);
  46.    move (xvmin, y0);
  47.    draw (xvmax, y0);
  48.    move (xvmin - 8 * character width,
  49.          y0 - line height DIV 3);
  50.    plot text (text (xmin, 7, 2));
  51.    move (xvmax - 3 * character width DIV 2,
  52.          y0 - line height DIV 3);
  53.    plot text (text (xmax, 7, 2)).
  54.  
  55. draw the axis y with annotation:
  56.    INT CONST x0 :: round (cx);
  57.    move (x0, yvmin);
  58.    draw (x0, yvmax);
  59.    move (x0 - 5 * character width,
  60.          yvmin + line height DIV 3);
  61.    plot text (text (ymin, 7, 2));
  62.    move (x0 - 5 * character width,
  63.          yvmax - 4 * line height DIV 3);
  64.    plot text (text (ymax, 7, 2)).
  65.  
  66. draw the graphics:
  67.    t := tmin;
  68.    move (round (fx (t) * sx + cx),
  69.          round (fy (t) * sy + cy));
  70.    WHILE t <= tmax
  71.    REP
  72.      t INCR delta t;
  73.      draw (round (fx (t) * sx + cx),
  74.            round (fy (t) * sy + cy))
  75.    ENDREP.
  76. ENDPROC graphics2;
  77.  
  78.  
  79. REAL PROC fy (REAL CONST t):
  80.    sin (t)
  81. ENDPROC fy;
  82.  
  83. REAL PROC fx (REAL CONST t):
  84.    sin (6.0 * t)
  85. ENDPROC fx;
  86.  
  87. program:
  88.    enter graphics mode;
  89.    graphics2 (0.0, 2.0 * pi, 200,
  90.               REAL PROC (REAL CONST) fx,
  91.               REAL PROC (REAL CONST) fy);
  92.    wait for confirmation ( 2 * graphics x limit DIV 3, 1);
  93.    leave graphics mode.
  94.