Monday, February 8, 2010

Mandelbrot Fractal - Part 3


In my last post I said I was going to show the fractal with colors, and here it is! In this post I'll describe colors in the Mandelbrot fractal.

In my last post I wrote some pseudocode you could use to draw the fractal. In the pseudocode I told you to count the number of times you use the formulas. That's an index for your pallete. You should be able to implement that easily.

If you draw it, though, you'll notice a problem. You can see "banding" in the fractal. No matter how high your iteration limit is, the banding will still be there. You can fix this by changing your formula. Up until now you were doing something like this:

i: index into pal
cnt: iteration counter

i = (pal_size * cnt) / limit
plot pallete[i]


The algorithm should be similiar to that. To eliminate banding, replace the algorithm to this:

i: index into pal
cnt: iteration counter

(calculate iteration formulas 4 more times)
cnt = cnt + 5 - ( log(log(|z|)) / log(2) )
i = (pal_size * cnt) / limit
plot pallete[i]

If you test it using these formulas, banding should be gone (mostly). Alter your pallete until you get something you like.

No comments:

Post a Comment