PROGRAM Graph2(Output);

    {------------------------------------------------
        Program 6.2 - Generate graphic representation
        (with X-axis) of the function:
        F(X) = exp(-X) * Sin(2*PI*X)
        Compare with Program 4.7
    -------------------------------------------------}

    CONST
        XLines = 16;    { line spacings per 1 abscissa unit }
        Scale = 32;     { character width per 1 ordinate unit }
        ZeroY = 34;     { character position of X axis }
        XLimit = 32;    { length of graph in lines }
        Ylimit = 68;    { height of graph in character width }
    TYPE
        Domain = 1..YLimit;
    VAR
        Delta,          { increment along abscissa }
        TwoPi,          { 2 * PI = 8 * ArcTan(1.0) }
        X, Y: Real;
        point: 0..XLimit;
        Plot, YPosition, Extent: Domain;
        YPlot: Array[Domain] OF Char;
BEGIN
    Delta := 1 / XLines;
    TwoPi := 8 * ArcTan(1.0);

    FOR Plot := 1 TO YLimit DO
        YPlot[Plot] := ' ';

    FOR Point := 0 TO XLimit DO BEGIN
        X := Delta * Point;
        Y := Exp(-X) * Sin(TwoPi * X);
        YPlot[ZeroY] := ':';
        YPosition := Round(Scale * Y) + ZeroY;
        YPlot[YPosition] := '*';

        IF YPosition < ZeroY THEN
            Extent := ZeroY
        ELSE
            Extent := YPosition;

        FOR Plot := 1 TO Extent DO
            Write(Output, YPlot[Plot]);

        WriteLn(Output);
        YPlot[YPosition] := ' '
    END
END.

