Mandelbrot in Android and C#

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!)

View 3D MPO photos with Google Cardboard

One thing that I’ve been meaning to get my hands on is Google Cardboard, which  is an extraordinary bit of technology that transforms your smartphone into a virtual reality display, for the cost of just a few dollars! I love the simplicity of the concept, and I especially like how it repurposes existing features of the mobile device, specifically how it uses the magnetic field sensor to implement a sliding magnetic button. Anyway, I bought mine from Unofficial Cardboard:

While familiarizing myself with the Cardboard SDK, I realized that a perfect application for Cardboard would be to view .MPO photos taken by 3D cameras. So I created a minimal Android app that automatically searches your device for .MPO files, and displays them for viewing with Cardboard!  You can find the app on the Google Play Store, and the source code on GitHub.

A few notes about the app:

  • It automatically searches your phone’s internal memory and external SD card, but only up to two folder levels deep. For best results, place the .MPO files in the root directory of the memory card.
  • It creates a slide show out of all the MPO files that it finds. You may advance through the slide show by using the magnetic Cardboard slider control. It does not currently allow any customization of the slide show (excluding/including files, custom ordering, etc). Stay tuned…

Experimenting with Google’s Project Tango

Recently I had the opportunity to play around with Project Tango from Google:

I whipped up a quick demo, based on the existing sample code from Google, that takes the real-time point cloud provided by the depth sensor and “records” it into a large buffer of points and displays all of it in real time (allowing you to move around a 3D area and record its geometry), and also allows you to save the point cloud to a file, for loading into an application such as Blender.

Here are some screenshots of the demo, after I used it to record the inside of my living room:

Deus ex machina

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.)

A poem by J. Jayson Poryk

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.