07-01-2003, 01:13 AM
With recursion you can draw a tree
..or create a maze.
Code:
DECLARE SUB tree (x%, y%, a!, l!, o%)
CONST right = 3.1415926# / 2
CONST dec1 = .9, dec2 = .2, dec3 = .77
CONST inc1 = .2, inc2 = .3, inc3 = .98
RANDOMIZE TIMER
SCREEN 12: WINDOW (240, 320)-(-239, -319)
DO
CLS
tree (0), (-200), (0), 70, 10
t! = TIMER + 1: DO: LOOP UNTIL TIMER > t!
LOOP UNTIL LEN(INKEY$)
SUB tree (x%, y%, a, l, o%)
STATIC temp, temp1
IF o% THEN
PSET (x%, y%)
temp = (RND - .5) * dec3
temp1 = (RND - .5) * inc3
x% = x% + l * COS(a + temp1 + right) + temp
y% = y% + l * SIN(a + temp1 + right) + temp
LINE -(x%, y%)
tree (x%), (y%), (a + inc1), l * dec1, o% - 1
PSET (x%, y%)
tree (x%), (y%), (a - inc1), l * dec1, o% - 1
END IF
END SUB
..or create a maze.
Antoni