For my coursework, I have decided to create a visualiser that demonstrates a bunch of sorting algorithms.
The modules that I am using are ‘Matplotlib’ & Tkinter.
The main reason why I am doing this for my NEA is because I was inspired by this:
I thought this was pretty cool and also satisfying to watch. I wanted to see if I could replicate this in Python.
I taught myself some basic Tkinter & Matplotlib to try and create this program. I have to admit that it took a long time to get the hang of it. But I am way more confident now than I was over a month ago.
- April 17th 2020 – This is me experimenting with Matploblib, I only managed to get basic sorts to work with some educated guesses of plt.show(). This was before I learned about FuncAnimation
- 1st May 2020 – I taught myself how generators work in Python alone with learning about the FuncAnimation. With this, I was able to get more complex sorts to work that had two modules to execute (the actual sorting part and the merging bit). I then implemented the animation frame into the more basic sorts. From then on, I had the FuncAnimation performing all my sorts. This saved me from repeating a bunch of lines in my code when educating where to put plt.show()
I then spent the better part of a month thoroughly understanding how Matplotlib & Tkinter fully works. I went over old sorts to understand what was entirely going on. I revised OOP more carefully. From then, I started from scratch. I first built my program into modules. I then took that working work and transformed it into a class. I then abstracted what I needed to get the bare minimum of my idea to work. A basic GUI. A few basic sorts, and it visualized.
- 19th May 2020 – I built the tkinter GUI. This wasn’t done in a class just yet. I was currently familiarizing myself with Tkinter. I managed to get it working, but it wasn’t intuitive and I had to close the tkinter menu in order to get the chosen sort to visual in matplotlib. I needed to get the graph to appear in the window. On the 20th May, I managed to transform the modular code into a class. But it still did the exact same thing.
- 21st May 2020 – I built some external programs first to try and teach myself how to get a matplotlib graph into a tkinter window. I managed to do it. I took this and implemented it into my program. The visualiser was coming together.
- 22nd May 2020 – I then took this design and made it more intuitive – I added buttons to the GUI, instead of typing out each letter to determine what sort to visualize. The buttons might seem weirdly place because the graph takes up a large grid, row, column size. The most easier way to fix this is by creating a second frame and putting the graph in that inside of the main frame I believe. UPDATE: Fixed
- 23rd May 2020- Added Quicksort
- 22nd May 2020 – Fixed a bug where Matplotlib still tries to draw the next frame even though the array has been sorted. This was fixed by adding ‘repeat = False’ into the FuncAnimation
- 23rd May 2020, Fixed a bug where an error was identified in the method: ‘ Tk.mainloop() ‘, but yet it didn’t affect the program in anyway. However, if the Tk.mainloop() was taken away. The program did not work. The Shell was informing that it was missing ‘self’ in the parameters, but adding self did not fix it. It was due to using the wrong variable in .mainloop(). By changing the variable to root, which is already is being passed through the class. It fixed it. I should of noticed something like that a lot earlier smh
470 total views, 1 views today