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
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"))
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 LETTER_FONT = pygame.font.SysFont('comicsans', 20)