/
rundemo
executable file
·44 lines (32 loc) · 1.06 KB
/
rundemo
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
#!/usr/bin/env python
from math import ceil, floor
import pygame
from pygame.locals import *
from pygame import Rect
from quad import QuadTreeNode
pygame.init()
screen = pygame.display.set_mode((800, 800))
root = QuadTreeNode(screen.get_rect())
done = False
clock = pygame.time.Clock()
while not done:
for event in pygame.event.get():
if event.type == QUIT:
done = True
elif event.type == KEYDOWN and event.key == K_ESCAPE:
done = True
elif event.type == MOUSEBUTTONDOWN:
root.add_point(pygame.mouse.get_pos())
screen.fill(0)
# draw quadtree
if hasattr(root, "collidepoint"):
active = root.collidepoint(pygame.mouse.get_pos())
screen.fill((80,80,80), active.rect)
if hasattr(root, "get_rects"):
for rect in root.get_rects():
pygame.draw.rect(screen, (170, 170, 170), rect, 1)
if hasattr(root, "get_points"):
for point in root.get_points():
pygame.draw.circle(screen, (255,255,255), point, 3)
pygame.display.flip()
clock.tick(30)