{------------------------------------------------------------------
    The following program plots a real-valued function f(x) by
    letting the X-axis run vertically and then writing an asterisk
    in positions corresponding to the coordinates. The position of
    the asterisk is obtained by computing Y = f(X), multiplying by
    the scale factor, rounding the product to the next integer, and
    then adding a constant and letting the asterisk be preceded by
    that many blank spaces.
 ------------------------------------------------------------------}

PROGRAM Graph1(output);
    {----------------------------------------------------
        Program 4.7 - Generate graphic representation of
        the function:
        f(X) = exp(-ٓX) * Sin(2*Pi*X)
    -----------------------------------------------------}

    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 }
    VAR
        Delta: Real;    { increment along abscissa }
        TwoPi: Real;    { 2 * Pi = 8 * ArcTan(1.0) }
        X, Y: Real;
        Point: Integer;
        YPosition: Integer;
BEGIN
    Delta := 1 / XLines;
    TwoPi := 8 * ArcTan(1.0);
    FOR Point := 0 TO XLimit DO
    BEGIN
        X := Delta * Point;
        Y := Exp(-X) * Sin(TwoPi * X);
        YPosition := Round(Scale * Y) + ZeroY;
        REPEAT
            Write(Output, ' ');
            YPosition := YPosition - 1;
        UNTIL YPosition = 0;
        WriteLn(Output, '*');
    END;
END.
