-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
65 lines (54 loc) · 1.87 KB
/
Copy pathmain.py
File metadata and controls
65 lines (54 loc) · 1.87 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
from rrt_algo import *
from draw import *
OBSTACLE_COUNT = 5
def create_obstacles():
obstacles = []
for _ in range(OBSTACLE_COUNT):
obstacle = (random.randint(OBSTACLE_RADIUS, WIDTH - OBSTACLE_RADIUS), random.randint(OBSTACLE_RADIUS, HEIGHT - OBSTACLE_RADIUS))
obstacles.append(obstacle)
return obstacles
def main():
screen, clock = initialise_map()
obstacles = create_obstacles()
start = None
goal = None
rrt = None
setting_start = 1
setting_background = 1
create_ob = 1
running = True
while running:
if setting_background == 1:
screen_fill(screen)
flip_display()
setting_background = 0
# Draw obstacles
if create_ob == 1:
for obs in obstacles:
draw_circle(screen, obs, OBSTACLE_RADIUS)
flip_display()
create_ob = 0
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.MOUSEBUTTONDOWN:
x, y = pygame.mouse.get_pos()
if not is_in_obstacle((x, y), obstacles):
if setting_start:
start = (x, y)
print(f"Start point set at {start}")
draw_circle(screen, start, 10, RED)
flip_display()
setting_start = 0
else:
goal = (x, y)
print(f"Goal point set at {goal}")
draw_circle(screen, goal, 10, RED)
flip_display()
rrt = RRT(start, goal, obstacles)
rrt.run(screen)
else:
print("Invalid point, try again.")
pygame.quit()
if __name__ == "__main__":
main()