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)
def main():
    numbers = []
    running = True
    # Add default values
    display.sizeBox.text = '100'
    display.algorithmBox.text = 'mergesort'
    while running:
        mouse = pygame.mouse.get_pos()
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False

            display.sizeBox.update(event)
            display.delayBox.update()
            display.algorithmBox.update(event)
            display.startButton.update()

            if display.startButton.active and not error_checking():
                # 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.text
                # Generates a random list
                numbers = randomList()
                # Executes the chosen algorithm
                runAlgorithm(algorithm.lower(), numbers)
                display.toDraw = True
        display.drawInterface(numbers, -1, -1, -1, -1)
示例#3
0
def main():

    numbers = []
    running = True
    # Add default values
    display.sizeBox.text = '100'
    display.algorithmBox.add_options(list(algorithmsDict.keys()))
    # display.algorithmBox.text = 'mergesort'
    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_list = list(range(0, display.numBars))

            if display.startButton.active and not error_checking():
                # 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 = randomList()
                # Executes the chosen algorithm
                runAlgorithm(algorithm.lower(), numbers)
                display.toDraw = True
        display.drawInterface(numbers, -1, -1, -1, -1, greenRows=a_list)
def main():
    numbers = []
    running = True
    # Add default values
    display.sizeBox.text = '100'
    display.algorithmBox.text = 'mergesort'
    while running:
        mouse = pygame.mouse.get_pos()
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False

            # In case the mouse is pressed
            if pygame.mouse.get_pressed() != (0, 0, 0):
                if display.delayBox.rect.collidepoint(mouse):
                    display.delayBox.write()
                elif display.sizeBox.rect.collidepoint(mouse):
                    display.sizeBox.isActive = True
                    display.algorithmBox.isActive = False
                elif display.algorithmBox.rect.collidepoint(mouse):
                    display.sizeBox.isActive = False
                    display.algorithmBox.isActive = True
                # In case the start button is pressed
                elif display.button_rect.collidepoint(mouse):
                    if error_checking(): continue
                    # Set the values given by the user
                    display.button = display.stopButton
                    display.numBars = int(display.sizeBox.text)
                    display.delay = display.delayBox.value - display.delayBox.rect.x - 6
                    algorithm = display.algorithmBox.text
                    # Generates a random list
                    numbers = randomList()
                    # Executes the chosen algorithm
                    runAlgorithm(algorithm.lower(), numbers)
                    display.button = display.playButton
                    display.toDraw = True
            # In case any key is pressed
            if event.type == pygame.KEYDOWN:
                if display.sizeBox.isActive:
                    display.sizeBox.write(event)
                elif display.algorithmBox.isActive:
                    display.algorithmBox.write(event)
        display.drawInterface(numbers, -1, -1, -1, -1)