-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
56 lines (48 loc) · 1.33 KB
/
main.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
# import libraries
import numpy as np
import quadtreemap
from recorder import Recorder
np.set_printoptions(precision=4)
WIDTH = 640
HEIGHT = WIDTH
maxlevel = 5
Point = quadtreemap.Point
recorder = Recorder(
"Quadtree",
extension="gif",
fps=60,
)
boundbox = quadtreemap.Rectangle(0, 0, WIDTH, HEIGHT)
map = quadtreemap.QuadTree(boundbox, maxlevel)
tapp = quadtreemap.Tree(WIDTH, HEIGHT)
def generateCircle(n=300):
deg = np.random.uniform(0, 360, n)
ang = deg * np.pi / 180
r = np.random.uniform(0, 200)
x = 2.5*WIDTH/4 + r*np.cos(ang)
y = 2.5*HEIGHT/4 + r*np.sin(ang)
xy = np.vstack([x, y]).transpose()
r1 = np.random.uniform(0, 5)
x1 = 0.7*WIDTH/4 + r1*np.cos(ang)
y1 = 0.7*HEIGHT/4 + r1*np.sin(ang)
xy1 = np.vstack([x1, y1]).transpose()
xy = np.vstack([xy, xy1])
print(xy.shape)
return quadtreemap.PointCloud(xy)
def generateQuarter(n=300):
xy = np.random.uniform(0,WIDTH, (n,2))
return quadtreemap.PointCloud(xy)
pcData = generateCircle(n=1000)
# print(pcData)
if __name__ == "__main__":
done = True
while not done:
pcData = generateCircle(n=10)
map.insert(pcData)
tapp.draw(map.root)
tapp.drawPCData(pcData)
tapp.update()
# recorder.save(tapp.screen)
done = tapp.eventCheck()
del pcData
map.print_tree()