-
Notifications
You must be signed in to change notification settings - Fork 1
/
l_system_test.py
108 lines (89 loc) · 2.52 KB
/
l_system_test.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
from l_system import LSystem
def draw_peano():
peano_omega = "L"
peano_expansion_rules = {
"L": "LFRFL-F-RFLFR+F+LFRFL",
"R": "RFLFR+F+LFRFL-F-RFLFR",
"F": "F",
"+": "+",
"-": "-"
}
peano = LSystem(peano_omega, peano_expansion_rules, 90, 2)
peano.print_pattern()
def draw_hilbert():
hilber_omega = "L"
hilbert_expansion_rules = {
"L": "+RF-LFL-FR+",
"R": "-LF+RFR+FL-",
"F": "F",
"+": "+",
"-": "-"
}
hilbert = LSystem(hilber_omega, hilbert_expansion_rules, 90, 3)
hilbert.print_pattern()
def draw_koch():
koch_omega = "F"
koch_expansion_rules = {
"F": "F+F-F-F+F",
"+": "+",
"-": "-"
}
koch = LSystem(koch_omega, koch_expansion_rules, 90, 3)
koch.print_pattern()
def draw_fractal_plant():
fractal_plant_omega = "X"
fractal_plant_expansion_rules = {
"X": "F+[[X]-X]-F[-FX]+X",
"F": "FF",
"[": "[",
"]": "]",
"+": "+",
"-": "-"
}
fractal_plant = LSystem(fractal_plant_omega, fractal_plant_expansion_rules, 25, 4)
fractal_plant.print_pattern()
def draw_cantor():
cantor_omega = "A"
cantor_expansion_rules = {
"A": "ABA",
"B": "BBB",
}
cantor_set = LSystem(cantor_omega, cantor_expansion_rules, 0, 2)
cantor_set.print_pattern()
def draw_sierpinsky():
sierpinsky_omega = "F-G-G"
sierpinsky_expansion_rules = {
"F": "F-G+F+G-F",
"G": "GG",
"+": "+",
"-": "-"
}
sierpinsky = LSystem(sierpinsky_omega, sierpinsky_expansion_rules, 120, 3)
sierpinsky.print_pattern()
def draw_fractal_tree():
fractal_tree_omega = "0"
fractal_tree_expansion_rules = {
"1": "11",
"0": "1{0}0",
"{": "{",
"}": "}",
}
fractal_tree = LSystem(fractal_tree_omega, fractal_tree_expansion_rules, 45, 3)
fractal_tree.print_pattern()
def draw_dragon_curve():
dragon_curve_omega = "F"
dragon_curve_expansion_rules = {
"F": "F+G",
"G": "F-G",
"+": "+",
"-": "-",
}
dragon_curve = LSystem(dragon_curve_omega, dragon_curve_expansion_rules, 90, 10)
dragon_curve.print_pattern()
def main():
# draw_fractal_tree()
# draw_sierpinsky()
# draw_koch()
draw_dragon_curve()
if __name__ == '__main__':
main()