Building a Platform to Visualize Algorithms

ACM is getting a new office! And with that, we've been promised a tv screen to put in the window, so that we may display things of our choosing, be it notices, announcements, or... algorithms! There's nowhere at UC where a passing student can pause and look at how an algorithm works, or just watch something cool in the computer science field. Due to the perfect location of our office, I think that showing visualizations of algorithms would be a really cool thing to do. And in the spirit of the recently concluded hacktoberfest, I wanted to build a platform where ACM members could contribute, and hopefully even learn something new.

Visualizer

The source code for this repository is on github. There were a number of things I new I wanted from this project. One of those things was the ability for people to contribute, despite their familiarity with Java or Swing.

Abstracting away the ugly parts

I set about abstracting creating a JPanel, dealing with animation threads, and resizing the window dynamically. I built an abstract class, Visualizer.java. This class handles resizing the drawing canvas, creating a thread for animation, and ensuring that implementations have all the necessary parts. An important part of the Visualization class is that it allows any implementations to presume a 1000x1000 pixel drawing canvas. This means that any future changes to the size of the application don't affect already made visualizations. It also handles control from the owning JFrame to the visualization, so that upon completion, a visualization can be replaced with the next one.

Reflection

Because people would be contributing to this project, I wanted pull requests to be as straightforward as possible. Contributors would create their class, overriding the necessary methods, and that's all. I didn't want it to be necessary to add to a manifest of visualizations, or change code outside of their added class for it to work. Luckily, Java has a nifty feature called reflection, which allows me to dynamically load classes. I built the running class of this project, MainFrame.java to handle arguments, which can tell it to load a specific class, or no arguments, which allow it to load all non-abstract classes that extend Visualizer.java.

Contributing

Interested in contributing? Head over to the github page and fork the project! Find a bug? Create an issue on github!