-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
66 lines (53 loc) · 2.63 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
import astar
import bfs
import insertion_sort
import sys
import bubble_sort
from utils import * # imports pygame
from pygame.locals import *
# Setup window
SCREEN_WIDTH = 550
SCREEN_HEIGHT = 630
pygame.display.set_caption("Algorithms Visualization")
_screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
_click = False
def run_main():
global _click
while True:
_screen.fill(DARK_SLATE_GRAY)
draw_text('Algorithms Visualization', pygame.font.SysFont('Lato', 40, True),
ORANGE_RED, _screen, SCREEN_WIDTH // 2, 50)
draw_text('Main Menu', pygame.font.SysFont('Lato', 30, True), ORANGE_RED, _screen, SCREEN_WIDTH // 2, 120)
underline_font = pygame.font.SysFont('Lato', 15)
underline_font.set_underline(True)
git_hub = draw_text('Project on GitHub', underline_font,
WHITE, _screen, 100, SCREEN_WIDTH - 20)
mouse_pos = pygame.mouse.get_pos()
# TODO: add calls here
a_star_btn = normal_button((125, 180), (100, 35), _screen, 'A Star', mouse_pos)
bfs_btn = normal_button((125, 230), (100, 35), _screen, 'BFS', mouse_pos)
insertion_btn = normal_button((325, 180), (120, 35), _screen, 'Insertion Sort', mouse_pos)
bubble_btn = normal_button((325, 230), (120, 35), _screen, 'Bubble Sort', mouse_pos)
#help_btn = normal_button((SCREEN_WIDTH - 120, SCREEN_WIDTH - 30), (100, 30), _screen, 'Help', mouse_pos, color=BLUE)
if _click:
set_click_listener(a_star_btn, mouse_pos, lambda: astar.run_visualization(_screen, SCREEN_WIDTH))
set_click_listener(bfs_btn, mouse_pos, lambda: bfs.run_visualization(_screen, SCREEN_WIDTH))
set_click_listener(insertion_btn, mouse_pos, lambda: insertion_sort.run_visualization(_screen, SCREEN_WIDTH))
set_click_listener(bubble_btn, mouse_pos, lambda: bubble_sort.run_visualization(_screen, SCREEN_WIDTH))
set_click_listener(git_hub, mouse_pos, lambda: webbrowser.open('https://github.com/Umair-Syed/Algorithms'
'-Visualization.git', new=2))
_click = False
# _click = is_clicked()
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
pygame.quit()
sys.exit()
if event.type == MOUSEBUTTONDOWN:
if event.button == 1:
_click = True
pygame.display.update()
run_main()