forked from LucasPilla/Sorting-Algorithms-Visualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
40 lines (33 loc) · 1.33 KB
/
main.py
File metadata and controls
40 lines (33 loc) · 1.33 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
import display
import pygame
from algs import algorithmsDict, runAlgorithm
from random import randint
# Global Variables: numBars, delay, toDraw, button
# They were declared in display.py
def main():
numbers = []
running = True
display.algorithmBox.add_options(list(algorithmsDict.keys()))
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
display.sizeBox.update(event)
display.delayBox.update()
display.algorithmBox.update()
display.startButton.update()
a_set = set(range(display.numBars))
if display.startButton.active:
# Set the values given by the user
display.numBars = int(display.sizeBox.text)
display.delay =\
display.delayBox.value - display.delayBox.rect.x - 6
algorithm = display.algorithmBox.get_active_option()
# Generates a random list
numbers = [randint(10, 400) for i in range(display.numBars)]
# Executes the chosen algorithm
runAlgorithm(algorithm.lower(), numbers)
display.toDraw = True
display.drawInterface(numbers, -1, -1, -1, -1, greenRows = a_set)
if __name__ == '__main__':
main()