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


Untitled4

Untitled5

Untitled7