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

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:

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:

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

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?

-
It looks like you are assigning colors based on breakpoints that scale (linearly?) with the maximum number of iterations. That is why the whole rectangle goes red at high iteration limits. You might want to go ahead and calculate with a high limit, then think about where the color breaks go. Say choose red for the fastest 10% of the pixels, yellow for the next 10%, etc. Or look at the width of bands (which may not be easy). – Ross Millikan Jan 10 '11 at 20:42
@Ross thanks for the idea...I actually hadn't thought of this. I will try to get it implemented tonight or tomorrow. – treeface Jan 10 '11 at 22:11
See: en.wikibooks.org/wiki/Fractals/Mathematics/Numerical#Zoom Remember also about precision of numbers you use : en.wikibooks.org/wiki/Fractals/Mathematics HTH – Adam Oct 14 '12 at 19:08

fractal colouring for deep zooms I have rendered such as e214 and "last lights on" have the palette applied in a loop, so it repeats every X number of iterations. can you colour it like that? If I find the journey of an animation has areas where contrasting colours are too far apart, then I increase the speed of the palette. ie: lower the value of X. - Then any change in the overall iteration value will not change the colour placement.

teamfresh

-
Thank you for taking the time to answer! I'm curious if you could expound a bit on what you mean by applying the palette in a loop? When you say "X number of iterations", what do you mean by "iterations"? Thanks again for helping out :-] – treeface Jan 10 '11 at 22:32
The fractal is made up from iterations - assign a a colour to each iteration. So say if you have 256 colours in your palette, you could repeat the palette every 256 iterations of the fractal formula but how you would go about this in javascript im not sure.... – fractal Jan 11 '11 at 0:36

This works pretty well, but don't ask me how I came up with it.

maxItValue=sqrt(abs(2*sqrt(abs(1-sqrt(5*scale)))))*66.5

-
What is scale in this formula? Does this work at extreme depths? – Jordan May 23 '12 at 13:39

If I understand you correctly, you are asking "what is the formula that tells you how many iterations to do to get the Mandelbrot set to have a 'nice' resolution at some given level of magnification?"

• "I'd need some method of finding something like an ideal max Iterations value depending on the zoom level" is not a well phrased question; for one thing, the concept of "ideal max iterations" is not well defined and could mean different things for different people.

• There is no easy way to make the video like the one you linked to, and I'm sure it took a very long time to make that one because each frame had to be resolved one at a time and then put back together. I have no way of knowing for sure, but I have always assumed that video was made by determining how many iterations for each frame (zoom level) to do one frame at a time, by trial and error.

That being said, I believe that the rapidity for which one point on the set converges has little/no effect on the convergence properties of many other points in the set which lie very close in distance; and therefore I don't expect that the formula you are looking for will exist.

The problem is that some regions (and some sub regions...) of the set require more iterations to resolve in a nice way than others.

However, if you included some additional information such as specifying the path you took as you zoomed in on the set, then it would probably be possible to find a formula that accomplishes the thing you are trying to do. I say this last point based only from my personal experience playing around with ChaosPro, not for any major theoretical reason.

-