-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplantgen.py
47 lines (35 loc) · 1.1 KB
/
plantgen.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
import random
# Define the L-system rules
rules = {
'F': ['FF+[+F-F-F]-[-F+F+F]', 'F[+F]F[-F]F', 'FF-[-F+F+F]+[+F-F-F]']
}
def generate_plant(axiom, rules, iterations):
# Start with the axiom
l_system_string = axiom
# Iterate the L-system
for _ in range(iterations):
new_l_system_string = ''
for character in l_system_string:
if character in rules:
new_l_system_string += random.choice(rules[character])
else:
new_l_system_string += character
l_system_string = new_l_system_string
return l_system_string
def generate_garden(size, iterations):
garden = []
for _ in range(size):
garden.append(generate_plant('F', rules, iterations))
return garden
def grow_plant(current_plant, iterations):
return generate_plant(current_plant, rules, iterations)
# Main function
def main():
# Parameters
seed = 'F'
iterations = 2
# Generate the L-system string
l_system_string = generate_plant(seed, rules, iterations)
print(l_system_string)
if __name__ == "__main__":
main()