Recently I uploaded some old-ish code to GitHub for displaying the Mandelbrot set in Android and in C#. Creating an interactive Mandelbrot explorer application (with pan and zoom) is one of my favorite ways of learning to develop for an unfamiliar platform, since it exercises many of the facets that are common between all platforms, such as rudimentary GUI design (with touch gestures, if possible), basic graphics programming, and optimizing for performance. Although I’m no longer a novice in either Android or C#, this code might still be relevant today. I’ve also gone through and modernized some of it, so that it doesn’t look too embarrassing. Here’s the source code for the Android app, and the source code for the C# application for Windows Forms (.NET). Feel free to check it out and fork!
In the Android code, some emphasis is placed on using JNI, so that the Mandelbrot fractal is rendered in native code to maximize speed, and also uses the native Bitmap API to directly manipulate the bitmap pixels. The C# code, on the other hand, renders the fractal in pure C# (not native code), but it does also manipulate the bitmap pixels directly by marshalling the bitmap to an integer array. Both versions of the code make use of multiple threads.
The C# application also allows you to select the way that the Mandelbrot is calculated. By default it uses simple double-precision floating point, which allows the fastest calculation and therefore lets you maximize the number of iterations for your exploration of the fractal. However, you may also set the calculation to use GMP arbitrary-precision numbers which, while being much slower than double-precision, allow you to zoom into the fractal by any amount (although the calculation will become slower and slower as you zoom in).
(Note: the Android code is now available as an app on the Google Play Store!)
No dictionary definition of deus ex machina would be complete without a picture of J.R.R. Tolkien’s Eagles. I mean, really. They save the day every single time! When will Gandalf learn to just have them on standby?! Here’s how the stories would go, if the Eagles were used correctly:
The Hobbit: If Gandalf Were Smart
Thorin Oakenshield solicits aid from the wizard Gandalf the Grey to develop a plan to recapture the mountain of Erebor and the vast treasure that lies within it.
Gandalf summons the Eagles and uses them to transport the company of dwarves to the Lonely Mountain. The dwarves proceed to lure the dragon Smaug out of the mountain, and he is promptly torn to shreds by the Eagles, allowing the dwarves to reclaim the treasure that was once theirs.
The Lord of the Rings: If Gandalf Were Smart
Gandalf meets Bilbo at his home in the Shire, and realizes that the magic ring that Bilbo possesses is actually the Ring of Power that is enabling the spirit of Sauron to keep enduring and building a stronghold in Mordor.
Gandalf puts the One Ring into an envelope, then wraps it in several layers of cloth, so that it becomes a bundle that can be easily gripped by an eagle-like creature.
Gandalf summons the Eagles, and puts the bundle into the claws of one of the creatures. He then sends this eagle to Mount Doom, along with the other Eagles for protection against a possible attack by the NazgÃ»l.
The Eagles make their way to Mount Doom at high altitude, virtually unnoticeable to any ground forces. Once positioned over Mount Doom, the Eagles swoop down, and the one that was carrying the Ring drops it into the lava. Whatever enemy forces were in pursuit of the Eagles are instantly neutralized by the destruction of the Ring, and there’s no further danger.
(Total time to complete the mission: <1 hour.)
Three men doing the work they love,
Three beds unfolding from above.
Inside the Stanton Building did they roam,
And in the public restroom did they make their home.
A quiet life, but not without excitement,
A changeover would bring them all delightment.
Dispensing soap, a paper towel, bowl full of mints,
With care did they conceal all hints
Of the duality of their existence,
But only in this lifestyle could they find subsistence.
O, all the simple pleasures each of them enjoys,
They are, and will forever be, the Bathroom Boys.