So I finally finished my rubbish sort visualization. It was more about learning a bit of Clojure interacting with Swing.
The code certainly isn't the prettiest, but it is very concise compared how it'd look in Java. The
canvasdoes the drawing, using
proxyto provide implementations of the
paintComponentand listen to tick events from the timer.
bubble-sortfunction returns a list which represents each intermediate stage of the bubble sort algorithm (well, it's not quite perfect as it includes all the swaps, not one at a time).
An atom is used to represent the mutable state (in this case, a counter which moves between 0 and the number of items in the list).
The full code is available in my Git repository here.