-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlindenmayer_system.py
48 lines (36 loc) · 1002 Bytes
/
lindenmayer_system.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""
__author__ = Willy Fitra Hendria
"""
def generate_lindenmayer_system(axiom, rules, max_steps):
current_seq = axiom
print("step= 0 ,\t",current_seq)
for i in range(max_steps):
next_seq = ""
for c in current_seq:
if c in rules:
next_seq += rules[c]
else:
next_seq += c
current_seq = next_seq
print("step=",i+1,",\t",current_seq)
print("---------------------")
print("Lindenmayer System #1 (Fibonacci)")
print("---------------------")
axiom = "C"
rules = {"C":"A", "A":"CA"}
max_steps = 5
generate_lindenmayer_system(axiom, rules, max_steps)
print("---------------------")
print("Lindenmayer System #2")
print("---------------------")
axiom = "R"
rules = {"R":"RS", "S":"ST", "T":"TR"}
max_steps = 5
generate_lindenmayer_system(axiom, rules, max_steps)
print("---------------------")
print("Sample with Constants")
print("---------------------")
axiom = "B"
rules = {"B":"F[-B]+B", "F":"FF"}
max_steps = 3
generate_lindenmayer_system(axiom, rules, max_steps)