-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
70 lines (60 loc) · 2.29 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import pygame
import sys
from ui import draw_menu
from algs.sorting import SortingVisualization
from algs.pathfinding import PathfindingVisualization
from algs.graph import GraphVisualization
from algs.backtracking import NQueensVisualization
pygame.init()
SCREEN_WIDTH = 1280
SCREEN_HEIGHT = 720
BG_COLOR = (0, 0, 0)
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption('Algorithm Visualizer')
visualizations = {
"NONE" : 0,
"SRT" : SortingVisualization(screen),
"BFS" : PathfindingVisualization(screen),
"GRPH" : GraphVisualization(screen),
"BCK" : NQueensVisualization(screen)
}
current = visualizations["NONE"]
clock = pygame.time.Clock()
running = True
while running:
time_delta = clock.tick(60)/1000.0
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_1:
current = visualizations["SRT"]
elif event.key == pygame.K_2:
current = visualizations["BFS"]
elif event.key == pygame.K_3:
current = visualizations["GRPH"]
elif event.key == pygame.K_4:
current = visualizations["BCK"]
elif event.key == pygame.K_ESCAPE:
current = visualizations["NONE"]
elif event.type == pygame.MOUSEBUTTONDOWN:
current.handle_mouse_click(event.pos, event.button)
visualizations["BFS"].ui_manager.process_events(event)
visualizations["GRPH"].ui_manager.process_events(event)
visualizations["BCK"].ui_manager.process_events(event)
if current == visualizations["NONE"]:
draw_menu(screen)
else:
current.render()
if current == visualizations["BFS"]:
visualizations["BFS"].ui_manager.update(time_delta)
visualizations["BFS"].ui_manager.draw_ui(screen)
elif current == visualizations['GRPH']:
visualizations["GRPH"].ui_manager.update(time_delta)
visualizations["GRPH"].ui_manager.draw_ui(screen)
elif current == visualizations["BCK"]:
visualizations["BCK"].ui_manager.update(time_delta)
visualizations["BCK"].ui_manager.draw_ui(screen)
pygame.display.flip()
pygame.quit()
sys,quit()