PROGRAM dreid; { Drei d Plot }

CONST n = 25;

{$I graphics.inc}

VAR x, y, xp, yp, i : integer;
    min, max        : ARRAY [0..xmax] OF byte;

{====================================================================}

FUNCTION z (x, y : integer) : integer;

VAR a, b : real;

BEGIN { z }
  a := (x-200)/100;
  b := (y-50)/25;
  z := trunc (-150*exp (-sqr(a)-sqr(b))+70*exp (-sqr(a)/4-sqr(b)/4))
END;  { z }

{====================================================================}

PROCEDURE draw;

BEGIN { draw }
  IF max [xp] = 0
    THEN
      BEGIN
        max [xp] := yp;
        min [xp] := yp
      END
    ELSE
      IF yp > max [xp]
        THEN
          max [xp] := yp
        ELSE
          IF yp < min [xp]
            THEN
              min [xp] := yp
            ELSE
              penup;
  moveto (xp, yp)
END;  { draw }

{====================================================================}

BEGIN { dreid }
  clrgbs;
  clrtbs;
  quad (0, 0, xmax, ymax);
  FOR i := 0 TO xmax DO
    BEGIN
      min [i] := 0;
      max [i] := 0
    END;
  FOR i := 0 TO n DO
    BEGIN
      write ('.');
      y := 100*i DIV n;
      FOR x := 0 TO 450 DO
        BEGIN
          IF x > 0
            THEN
              pendown
            ELSE
              penup;
          xp := 20+x+y;
          yp := 50+y+z (x, y);
          draw
        END
    END;
  hardcopy2
END.  { dreid }
