Repository navigation
Expand file tree
/
Copy pathcountPoints_temp.py
More file actions
110 lines (84 loc) · 3.59 KB
/
Copy pathcountPoints_temp.py
File metadata and controls
110 lines (84 loc) · 3.59 KB
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
109
110
import pygame,time,random
from graph.color import *
#from graph.points import pointsMany as points
from Trees.twoD_tree import points,root
import math
from algorithms.data_struct.queue import queue
pygame.init()
screen_width,screen_height = 1200,700
screen = pygame.display.set_mode((screen_width,screen_height))
screen.fill(Black)
def print_lines(pos,vertical,XL = 10,YD = 10,XR = screen_width-200,YU = screen_height-50):
x,y = pos
if vertical: pygame.draw.line(screen,Cyan,(XL,y),(XR,y))
else: pygame.draw.line(screen,Red ,(x,YD),(x,YU))
pygame.display.update()
def print_point(position, color= White,radius = 4, index=-1):
pygame.draw.circle(screen,color,position,radius)
if index > -1:
font = pygame.font.Font('freesansbold.ttf',14)
text = font.render( str(index),True, White)
screen.blit(text,text.get_rect(center = position))
pygame.display.update()
def arrow(screen, start, end, lcolor = Light_grey, tricolor = Black, trirad= 4, thickness=2):
pygame.draw.line(screen, lcolor, start, end, thickness)
rotation = (math.atan2(start[1] - end[1], end[0] - start[0])) + math.pi/2
rad = 180/math.pi
pygame.draw.polygon(screen, tricolor, (
(end[0] + trirad * math.sin( rotation ), end[1] + trirad * math.cos( rotation )),
(end[0] + trirad * math.sin(rotation - 120*rad), end[1] + trirad * math.cos(rotation - 120*rad)),
(end[0] + trirad * math.sin(rotation + 120*rad), end[1] + trirad * math.cos(rotation + 120*rad))
)
)
pygame.display.update()
for point in points:
print_point(point)
xL,yD,xR,yU = 10,10,screen_width,screen_height
vertical = False
Q = queue()
Q.insert( (root,xL,yD,xR,yU, vertical) )
pause = False
running = True
while running :
# pygame stuff:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit() #exit pygame,
running = False #exit() program
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
pause = not pause
time.sleep(0.2)
if pause:
continue
if Q.not_empty():
cur,xL,yD,xR,yU,vertical = Q.pop()
else: continue
print(cur.x,cur.y)
print_point((cur.x,cur.y),(vertical)*Cyan + (not vertical)*Red,radius = 6)
print_lines((cur.x,cur.y),vertical,xL,yD,xR,yU)
time.sleep(0.5)
if vertical == True:
#print_point((cur.x,cur.y),Cyan,radius = 6)
if cur.right:
Q.insert( (cur.right, xL, cur.y , xR , yU , not vertical) )
arrow(screen, (cur.x,cur.y),(cur.right.x,cur.right.y))
#print_point((cur.right.x,cur.right.y),Red,radius = 6)
time.sleep(0.2)
if cur.left :
Q.insert( (cur.left , xL, yD , xR , cur.y , not vertical ) )
arrow(screen, (cur.x,cur.y),(cur.left .x,cur.left .y))
#print_point((cur.left.x,cur.left.y),Red,radius = 6)
time.sleep(0.2)
else:
#print_point((cur.x,cur.y),Red,radius = 6)
if cur.right:
Q.insert( (cur.right,cur.x,yD,xR,yU, not vertical) )
arrow(screen, (cur.x,cur.y),(cur.right.x,cur.right.y))
#print_point((cur.right.x,cur.right.y),Cyan,radius = 6)
time.sleep(0.2)
if cur.left :
Q.insert( (cur.left ,xL,yD,cur.x,yU, not vertical) )
arrow(screen, (cur.x,cur.y),(cur.left .x,cur.left .y))
#print_point((cur.left.x,cur.left.y),Cyan,radius = 6)
time.sleep(0.2)