[Math] A way to determine the ideal number of maximum iterations for an arbitrary zoom level in a Mandelbrot fractal

fractalsgeometry

I've created a JavaScript-based fractal drawer which you can see here:

http://jsfiddle.net/xfF3f/12/

As you're probably all aware, a Mandelbrot Set is created by iterating over pixels as though they were coordinates on the real and imaginary planes. Each pixel then has a real and an imaginary part (like all complex numbers) which can be fed into an iterative loop of its own:

$ z = z^2 + c $

Where both z and c are complex numbers, z starts at 0, and c is the value of our pixel. If you run this a bunch of times, the squared modulus of z (|z|) will either stay below a limit you set (6 in my fractal drawer) or it will go above the limit. If it goes above the limit, you break the iteration and consider that pixel to be outside of the set. When this happens, you color that pixel a certain color depending on how big |z| has gotten and how many iterations it took to determine that it's outset the set. (See more on the formula used in my drawer here: Continuous coloring of a Mandelbrot fractal)

So given all this, we can say that a higher max iteration value will tell you with greater precision whether or not a point is in the set. It will also take more time to run because it's doing more calculations per pixel. There are also other visual factors…

If you start at a full zoom out and run the plot with a maxIterations value of 50, 100, and 300, you get this:

mandelbrot full zoom out with max iteration values of 50, 100, and 300

So you can see that while the detail of the edge of the set does get better as you increase the maxIterations value, the pixels outside the set are almost all red. At this zoom level, I'd say something like 50 iterations would be an ideal balance of color variation and edge detail.

Now if you zoom in to some arbitrary level keeping 50 maxIterations, you will begin to see something like this:

arbitrarily zoomed set at 50 maxiterations

The detail is horrible and the colors are also a bit homogeneous. So let's see what happens if we keep the same zoom level and change the maxIterations number to 80, 120, 250, 500, 1000, and 2000 (remember, the coordinates and zoom are exactly the same in all images, the only difference is the maxIterations value):

zoomed in changing only the number of maxIterations

As usual, increasing the maxIterations value too much leaves most of the points outside of the set red. Here I'd say something between the second (120 maxIterations) and third (250 maxIterations) is more or less ideal.

This is all relatively simple to do one image at a time with your eye and some tinkering, but this would be very difficult to do if I were to create a zoom like this: http://vimeo.com/1908224. I'd need some method of finding something like an ideal maxIterations value depending on the zoom level.

So after all of this, my question is: is there some such method? If not, where might I start to look in order to figure this out for myself? Am I thinking about this wrong? Is there a more obvious solution that I'm missing?

Thanks in advance!

Best Answer

As this graph shows, the behaviour of normalized iteration counts of points near the Mandelbrot set varies widely, indicating that attempts at a formula based on scale factors is doomed to fail.

Families of points in the Mandelbrot set

In any case the ideal number of iterations is infinite. For views with no interior regions visible it is preferable to structure computations such that they can be incremental without a fixed iteration limit, as all pixels will escape eventually. For views with interior regions visible one needs a limit, but this can be set dynamically by considering the behaviour of the pixels - maybe keep doubling the limit until no more pixels have escaped. Interior checking can help speed this up.

How to colour the iterations once you have calculated them is an aesthetic matter that has been addressed by the accepted answer. I do also recommend distance estimation as a way to make filaments uniformly visible.