-
Notifications
You must be signed in to change notification settings - Fork 2
/
visualizer.py
46 lines (35 loc) 路 1.04 KB
/
visualizer.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
import pygame
import algorithims
import sys
import os
dim = (1024, 512)
algorithims = {"MergeSort": algorithims.MergeSort()}
win = pygame.display.set_mode(dim)
win.fill(pygame.color("#a48be0"))
def check_quit():
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
def update(algorithim, swap1=None, swap2=None, win=win):
win.fill(pygame.color("#a48be0"))
pygame.display.set_caption("Merge Sort Algorithim")
k = int(dim([0]/len(algorithim.array)))
for i in range(len(algorithim.array)):
# Green when sorting
colour = (0, 0, 255)
if swap1 == algorithim.array[i]:
colour = (0 ,255, 0)
elif swap2 == algorithim.array[i]:
colour = (255, 0, 0)
pygame.draw.rect(win, colour, (i*k), dim[i], k, -algorithim.array[i])
check_quit()
pygame.display.update()
def main(args):
try:
algorithim = algorithims[args[0]]
_, timeElapsed = algorithim.run()
except:
print("An error has occured")
if __name__ == "__main__":
sys.argv.append("MergeSort")
main(sys.argv)