Skip to content

Commit 528c7b4

Browse files
committed
added lsystem sample
1 parent 2e4112e commit 528c7b4

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

graphics 4/lsystem.bas

+22-26
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
rem https://en.wikipedia.org/wiki/L-system
22
const fg_col = rgb(154, 170, 53)
33
const bg_col = rgb(238, 241, 221)
4+
color fg_col, bg_col
45

56
sub draw_turtle(script, x, y, stem, turn, angle)
6-
local a, stack, i, idx, x2, y2
7+
local a, stack, i, idx, x2, y2, col
78
dim stack
9+
cls
810
for i = 0 to len(script)
911
select case mid(script, i, 1)
1012
case "F", "1", "0" ' draw forward from current position
@@ -26,6 +28,7 @@ sub draw_turtle(script, x, y, stem, turn, angle)
2628
delete stack, idx, 1
2729
end select
2830
next i
31+
showpage
2932
end
3033

3134
func create_lsystem(byref rules, byref variables, maxDepth, s, depth)
@@ -53,24 +56,16 @@ sub show_plant
5356
local maxDepth = 6
5457
local rules = {"X" : "F+[[X]-X]-F[-FX]+X", "F" : "FF"}
5558
local variables = ["X", "F"]
56-
local angle = 35
57-
local stem = 4
59+
local stem = 3
5860
local script = create_lsystem(rules, variables, maxDepth, "X", 0)
61+
local a = 35
5962

60-
for j = 0 to 10
61-
cls
62-
draw_turtle(script, x, y, stem, 20, 90)
63-
showpage
64-
delay(100)
65-
cls
66-
draw_turtle(script, x, y, stem, 36, 90)
67-
showpage
68-
delay(100)
69-
cls
70-
draw_turtle(script, x, y, stem, 39, 90)
71-
showpage
72-
delay(100)
73-
next j
63+
draw_turtle(script, x, y, stem, 35, 90)
64+
delay(1200)
65+
for a = 35 to 80 step 1
66+
draw_turtle(script, x, y, stem, 45-a, 90)
67+
delay(20)
68+
next a
7469
end
7570

7671
sub show_tree
@@ -80,14 +75,15 @@ sub show_tree
8075
local rules = {"1":"11", "0":"1[-0]+0"}
8176
local variables = ["1", "0"]
8277
local angle = 70
83-
local stem = 4
84-
85-
local script = create_lsystem(rules, variables, maxDepth, "0", 0)
86-
draw_turtle(script, x, y, stem, angle, 90)
78+
local stem = 2
79+
for d = 2 to 8
80+
local script = create_lsystem(rules, variables, d, "0", 0)
81+
draw_turtle(script, x, y, stem, angle, 90)
82+
delay(120)
83+
next d
8784
end
8885

89-
color fg_col, bg_col
90-
cls
91-
'show_plant
92-
show_tree
93-
? "ok"
86+
'show_tree
87+
'delay(1000)
88+
show_plant
89+
pause

0 commit comments

Comments
 (0)