A Julia set generator

We found a blog postFractals in Haskell

by Greg Heartsfield about generating different fractal sets using Haskell. We were especially attracted to the Julia Set and set about adapting it to our needs.

The first step was to download the source from the darcs repository. Second, we wanted to update the module layout and build process, so we revised the project layout and .cabal file, as well as initializing it as a Stack project.

We added this to our stack.yaml file so that Nix would fetch our dependencies for us:

We also modified the project’s structure a little to match our expectations for project setup that includes executablesOur fork of this package along with updated installation instructions and some pretty pictures.

(see below).

Producing the picture

The Julia generator is set up to generate them in greens, and it took some fiddling before we were able to produce purples, although in retrospect it seems simple. The input Int value that forms the basis of the rgb coloring comes from the julia function, that is, the actual fractal generator. But by fiddling with the values of the other arguments to the rgb function relative to that Int, we were able to get purples.

The generator is set up so that what appears to be the “background” color is black by default. This turned out not to be a “background” but the decreasing value of that Int input (mentioned above as the input value to the color) as it iterates to the outer edges of the pattern. Since the original version of the rgb function manipulated the values only with multiplication, it was only producing more zeroes, leading to total blackness.

We therefore started using addition to ensure that the rgb values never get to zero – black – at the outer edges.

Finally, we did some fiddling with the numbers for the Size and Window values to increase the resolution. We found the Size values and the Window values are best adjusted together, otherwise the image can become very stretched and distorted.