A nice way to render fractals like Julia o Mandelbrot sets of polynomails is to use the distance from the current pixeel to the boundary of the set. This avoids the usual
aliasing problem of rendering fractals, where details are just to small to be visible thru the sampling of the image. Without going into details in this article (go to
the math section for that), the distance to the Mandelbrot set is defined by the Green function G(c) (or Hubbard-Douady potential) as
|
|  |
|
where |
|
 |
| since the derivative G' is |
|  |
|
we have that |

Basically this means than during our regular iteration loop we need to keep track of both Zn as usual and of it's derivative Z'n. If we are rendering the standard
Mandelbrot set with

then simple derivation rules give

|
|
The Mandelbrot set rendered with the distance formula. Click to enlarge
|
float calcDistance( float a, float b )
{
Complex c( a, b );
Complex z( 0.0f, 0.0f );
Complex dz( 1.0f, 0.0f );
float m2;
for( int i=0; i<1024; i++ )
{
dz = 2.0f*z*dz + 1.0f;
z = z*z + c;
m2 = Complex::ModuloSquared(z);
if( m2>1e20 )
{
return 0.0f;
break;
}
}
// distance estimation: G/|G'|
return sqrtf( m2/Complex::ModuloSquared(dz) )*.5f*logf(m2);
}
You can now use d to index in a gray scale gradient to create images as the ones below (you can click the images to see a higher resolution version):
|