Mandelbrot Set in Haskell

I recently decided to renew my Haskell skills, and this is the first result – very simple implementation of Mandelbrot Set in Haskell using Haskell Graphics Library – the source code.

Mandelbrot Set

Obviously there is a bug in X11 for OSX as not all the paths are set correctly. For that reason, before running HGL, we need to set environment variable:

DYLD_LIBRARY_PAT­H=/usr/X11R6/lib

During implementation I found a bug of HGL. As I did not find a proper way of drawing pixels, I had been drawing them as a line of size ‘1‘. This worked until I started using colours to distinguish between the speeds of convergence. I found out that to draw the pixel in colour, it needs to have at least size ‘2‘.

It was not easy to draw the colours either – essential is to spread the colour spectrum uniformly. This function is easy to change and makes huge differences in result picture:

highlight i | i < 185 = i | otherwise = (i-184)*20

As the implementation is very simple and not parallelized, it is actually quite slow. I did not figure out, how to improve it – I would appreciate any suggestions.

February 16, 2010
leave a comment.