-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSymulator.py
More file actions
77 lines (53 loc) · 1.85 KB
/
Symulator.py
File metadata and controls
77 lines (53 loc) · 1.85 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
import pygame
from Path import Path
# size of screen:
width, height = 1200, 510 # height will be changed to suit the size of the board
# sizes (mm)
x_size_board = 34.2 + 200
y_size_board = 114.3
x_size_robot = 20.3
y_size_robot = 15
# distance between wheels (mm):
wheel_dis = 420
# image of robot and image of board:
image_robot = "resources/images/Electbot.png"
image_board = "resources/images/Map2023.png"
def display_screen():
pygame.font.init()
mm_px = x_size_board / width
new_height = round(y_size_board / x_size_board * width)
x_robot = (x_size_robot / x_size_board) * width
y_robot = (y_size_robot / y_size_board) * new_height
screen = pygame.display.set_mode([width, new_height])
path = Path(width, new_height, 0, 0,
x_robot, y_robot, wheel_dis,
image_board, image_robot, mm_px)
path.recover_path_from_rtf_file()
simulator_screen(screen, path)
path.PrintImportantPositions_to_rtf_file()
path.print_FLL_path_to_rtf_file()
path.print_FRC_path_to_rtf_file(50, 0.9)
def get_mouse_clicked_pos():
pressed = pygame.mouse.get_pressed(3)
pos = pygame.mouse.get_pos()
return pressed[0], pos[0], pos[1]
def simulator_screen(screen, path):
path.work = 0
while path.work < 2:
# update the screen
pygame.display.flip()
# clear the screen before drawing it again
screen.fill(0)
# get user input
press, x, y = get_mouse_clicked_pos()
events = pygame.event.get()
pressed_keys = pygame.key.get_pressed()
# change the path according to the user's input
path.change(press, x, y, events, pressed_keys)
path.update_changes()
# draw the new path on the screen
path.draw(screen, path.start_x, path.start_y)
def main():
display_screen()
if __name__ == '__main__':
main()