A lovingly-crafted collection of physics lessons bubbled up through my programming community. They featured a handful of cool illustrations and simulations. Not to drag them through the mud, but one of the simulations — a demonstration of electrical charges — had quite poor performance. It was small as a postage stamp, pixelated, and ran at a slow frame rate. As a challenge, I decided to see if I could implement a similar simulation with better performance, using my bag of programming tricks. As you can (hopefully) see from the full-screen, fast-playing result above, it was a success. I took liberties with the physics model, for the sake of making a more visually playful result. Overall this was a fun exercise.
Reload the page to generate a different random distribution of positive/negative charges. Go here to play with an interactive version, where you can click/tap to toggle a single charge's sign, and move that charge with your mouse/finger. When you stop moving, it'll take off on its own, and then snap back to you when you start moving again.