! Graphic example of recursive algorithm
!
SET MODE "LACEHIGH4"
RANDOMIZE
SET BACKGROUND COLOR "BLACK"

SET WINDOW -1000, 1000, -700, 700
LET Angle = 90
LET Level = 6
LET BLength = 80
LET dAngle = 20

DO
   CALL Show_Text
   DRAW Branch(0, 0, Angle, dAngle, BLength, Level)
   LET dAngle = dAngle + 5
   PAUSE 5
LOOP until key input

END


PICTURE Branch(x,y,Angle,dAngle,BLength,Level)

    OPTION ANGLE degrees

    IF Level = 0 then
       DRAW Flower(x,y)
    ELSE
       LET xend = x + BLength*cos(Angle+dAngle)
       LET yend = y + BLength*sin(Angle+dAngle)
       PLOT x,y; xend,yend

       ! Branch calls itself recursively
       DRAW Branch(xend,yend,Angle+dAngle,dAngle,BLength,Level-1)

       LET xend = x + BLength*cos(Angle-dAngle)
       LET yend = y + BLength*sin(Angle-dAngle)
       PLOT x,y; xend,yend

       ! Branch calls itself recursively
       DRAW Branch(xend,yend,Angle-dAngle,dAngle,BLength,Level-1)
    END IF

END PICTURE



PICTURE Flower(x,y)

    OPTION ANGLE degrees

    ASK MODE m$
    IF m$ <> "B/W" then SET COLOR "green"
    FOR angle = 0 to 360 step 30
        PLOT x,y; x+30*cos(angle),y+30*sin(angle)
    NEXT angle
    IF m$ <> "B/W" then SET COLOR "yellow"

    IF key input then STOP

END PICTURE



SUB Show_Text

    CLEAR
    ASK MODE m$
    IF m$ <> "B/W" then SET COLOR "red"
    ASK MAX CURSOR maxrow, maxcol

    LET A1$ = "RECURSIVE TREE PATTERNS"
    SET CURSOR 1,(maxcol-LEN(A1$))/2
    PRINT A1$

    LET A2$ = "drawn in True BASIC"
    SET CURSOR maxrow-1,(maxcol-LEN(A2$))/2
    PRINT A2$
    IF m$ <> "B/W" then SET COLOR "yellow"

END SUB


