-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflyweight.py
42 lines (35 loc) · 1.07 KB
/
flyweight.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
#!/usr/bin/python
#coding:utf8
#享元模型,复用id,降低内存使用率
import random
from enum import Enum
from tree import Tree,TreeType
def main():
rnd = random.Random()
age_min, age_max = 1, 30
min_piont, max_point = 0, 100
tree_counter = 0
for _ in range(10):
t1 = Tree(TreeType.apple_tree)
t1.render(rnd.randint(age_min, age_max),
rnd.randint(min_piont, max_point),
rnd.randint(min_piont, max_point)
)
tree_counter += 1
for _ in range(3):
t1 = Tree(TreeType.cherry_tree)
t1.render(rnd.randint(age_min, age_max),
rnd.randint(min_piont, max_point),
rnd.randint(min_piont, max_point)
)
tree_counter += 1
for _ in range(5):
t1 = Tree(TreeType.peach_tree)
t1.render(rnd.randint(age_min, age_max),
rnd.randint(min_piont, max_point),
rnd.randint(min_piont, max_point)
)
tree_counter += 1
print(Tree.pool)
if __name__ == '__main__':
main()