def main(win): height_init = gen(20) height = to_height(height_init) height_color = [BLACK for i in range(len(height))] run = True executing = False number_toggle = True title = header_font.render('BUBBLE SORT VISUALISER.', 30, BLACK) ops = 0 ops_text = header_font.render(f'Ω = {ops}', 30, BLACK) while run: pygame.time.delay(10) if executing == False: win.fill(WHITE) show(height, win, height_color, number_toggle) toggle_number(height, win) win.blit(title, (20, 460)) win.blit(ops_text, (470, 460)) pygame.display.update() else: ops = algorithms.BubbleSort(height, win, show, height_color, number_toggle, title, ops, header_font, WHITE, BLACK, GREEN, RED) ops_text = header_font.render(f'Ω = {ops}', 30, BLACK) win.blit(ops_text, (470, 460)) executing = False for event in pygame.event.get(): if event.type == pygame.QUIT: run = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: executing = True
import algorithms import time import os import sys import pygame # Set the window length and breadth (Make sure that the breadth is equal to size of array. [512]) dimensions = [1024, 512] # List all the algorithms available in the project in dictionary and call the necessary functions from algorithms.py algorithms = { "SelectionSort": algorithms.SelectionSort(), "BubbleSort": algorithms.BubbleSort(), "InsertionSort": algorithms.InsertionSort(), "MergeSort": algorithms.MergeSort(), "QuickSort": algorithms.QuickSort() } # Check list of all the available sorting techniques using 'list' if len(sys.argv) > 1: if sys.argv[1] == "list": for key in algorithms.keys(): print(key, end=" ") # Display the available algorithms print("") sys.exit(0) # Initalise the pygame library pygame.init() # Set the dimensions of the window and display it display = pygame.display.set_mode((dimensions[0], dimensions[1])) # Fill the window with purple hue display.fill(pygame.Color("#a48be0"))
import algorithms import time import os import sys import pygame # Set the window length and breadth (Make sure that the breadth is equal to size of array. [512]) dimensions = [1024, 512] # List all the algorithms available in the project in dictionary and call the necessary functions from algorithms.py algorithms = {"SelectionSort": algorithms.SelectionSort(), "BubbleSort": algorithms.BubbleSort(), "InsertionSort": algorithms.InsertionSort(), "MergeSort": algorithms.MergeSort(), "QuickSort": algorithms.QuickSort()} # Check list of all the available sorting techniques using 'list' if len(sys.argv) > 1: if sys.argv[1] == "list": for key in algorithms.keys(): print(key, end=" ") # Display the available algorithms print("") sys.exit(0) # Initalise the pygame library pygame.init() # Set the dimensions of the window and display it display = pygame.display.set_mode((dimensions[0], dimensions[1])) # Fill the window with purple hue display.fill(pygame.Color("#a48be0")) def check_events(): # Check if the pygame window was quit for event in pygame.event.get(): if event.type == pygame.QUIT: def update(algorithm, swap1=None, swap2=None, display=display): # The function responsible for drawing the sorted array on each iteration
K_SPACE, K_ESCAPE, QUIT, ) import algorithms as alg import math pygame.init() #Dimensions and fill color WIDTH = int(1024 * 1.5) HEIGHT = 860 FILL_COLOR = (245,255,250) RED = (255,99,71) # algorithms dict algorithms = {"Selection Sort": alg.SelectionSort(), "Bubble Sort": alg.BubbleSort(), "Insertion Sort": alg.InsertionSort(), # "Merge Sort": algorithms.MergeSort(), "Quick Sort": alg.QuickSort(), 'Heap Sort': alg.HeapSort(), 'Random': None} # button variables b_width = 100 b_height = 30 gap = 10 coordinates = [] b_text = algorithms.keys() start_pos = (10*gap,HEIGHT - (40+b_height)) #fonts