# Continuous coloring of a Mandelbrot fractal

I've recently started making a small fractal app in Javascript using the famous Mandelbrot bulb $(z = z^2 + c)$. I've been trying to find the best method of coloring the points on the complex plane, and I've come across some very interesting ideas:

http://linas.org/art-gallery/escape/escape.html

http://en.wikibooks.org/wiki/Fractals/Iterations_in_the_complex_plane/Mandelbrot_set#Real_Escape_Time

So I've been focusing on this "normalized iteration count algorithm" and I've run into a small mental hurdle sorting out what needs to be calculated. Basically, I'm confused about the first equation that shows up in that second link. Assuming we have a complex number $Z$ which is the end result of $n$ iterations. I can't quite figure out what "Zx2" or "zy2" is and how how one might add them together or take the square root of their sum. Is that just shorthand for some basic complex operators, or is there something else going on? Basically, my problem is that I'm not particularly good at reading mathematical notation in this area.

Anyway...any directional guidance you can offer would be extremely helpful. Thanks in advance!

-

Based on the C code given there, Zx is just the real part $\Re z$ and Zy is just the imaginary part $\Im z$.

Remember that the complex iteration formula for the Mandelbrot set

$z=z^2+c$

when expanded to real variables looks like

$x=x^2-y^2+u$

$y=2xy+v$

where $z=x+iy$ and $c=u+iv$.

The variables with a 2 appended are the squares, as can be seen from how they were defined, so for instance $|z|=\sqrt{x^2+y^2}$ is sqrt(Zx2+Zy2) which is used for determining how much the iteration diverges (escapes to infinity), which is used by the coloring functions.

-
$z_i$ of course is the ith iterate, so just take |zi|=sqrt(Zx^2+Zy^2), take the binary logarithm twice, subtract from the iteration number $i$ (it gets confusing to use i as an iteration counter when dealing with complex quantities :P ), and divide by the maximum number of iterations. This is how the coloring was done. – J. M. Sep 4 '10 at 22:21
Thanks a lot, J.M.! This is really helped me out a lot. – treeface Sep 4 '10 at 23:35

edit: "Zx2" and "Zy2" are defined in the C code in the second code block at this point in your wikibooks link. They are the squares of the real and imaginary parts, respectively, of $z$.

I'm not sure if it's exactly the same, but what I've used is: $$n-\log\left(\frac{\log(|z|)}{\log(r)}\right)$$ where $z$ is the result of $n$ iterations and has just escaped as noted by $|z|>r$ (where $r$ is the escape radius). This generates real numbers in $[0,n)$, so you could divide by $n$ to end up with a number in $[0,1)$.

-
Great answer, Isaac! I wish I could give both you and J.M. the answer. – treeface Sep 4 '10 at 23:36