I created this project to learn pygame and I wanted to create a Sorting Algorithm Visualizer from a long time.
- Menu to select Different Sorting Algorithms
Play&Pausebutton to control the VisualizationResetButton to reset the data on the screen- Each Algorithm has different visualization; the explanation of each visualization can be found on my website colilhasnel.com
- You can run the command
pip install -r requirements.txtin powershell. - The requirements are :
- python3
- pygame
- Run the
Visualizer.pyas a python file
- Add a
select_algorithm_buttonobject inVisualizer.py/algorithms_menufunction- The format should be
GLOBAL_INFO.algorithm_buttons["Algorithm Name"] = select_algorithm_button( algorithm_number, "Algorithm Name", display_algorithms.algorithm_function) - algorithm_number = Decides the position of button on the Menu Screen, Each algorithm has a unique algorithm_number
- "Algorithm Name" = This is what you think it is. It should be a string
- display_algorithm.algorithm_function = This points to the actual visualization function in
display_algorithm.pyfile
- The format should be
- Add a
algorithm_funcitonindisplay_algorithm.pyfile- This should be a
<generator>function. Read more on generator functions and objects here - You should code the entire algorithm in this funciton
- Update
global_info.colorarray wherever you want to show a swap or highlight a particular element- Use your own creativity to make better visualizations
- Add
global_info.draw_data(j)to update that particular index as per the color defined- If no
jargument is passed,global_info.draw_data()will update the entire Data
- If no
- add
yieldat appropriate places forPausefunction to work - Refer
bubble_sortfunction to understand how to add visualization on iterative algorithms - Refer
quick_sortfunction to understand how to add visualization on recursive algorithms
- This should be a
- Selection Sort, Insertion Sort, Radix Sort Visualizations are to be improved
- Adding a '+' and '-' button to increase or decrease the data size from UI
- Adding buttons to control fps
- As of 20/7/2023, I am concluding this project. I have added most of the functions that I wanted to. The only task remaining is to add many more sorting algorithms. All contributions are welcome.