fractal-haskell is a tool written in haskell (duh!) that draws Mandelbrot fractals. It is capable of generating stunning high resolution renders, both stills and animated, of the Mandelbrot set fractal featuring smooth colorful gradients.
This is just an example of what it can do!
- Drawing mandelbrot set
- Integer escape time
- Real escape time
- Greyscale or colored renders
- Continuously colored with gradient
- Customizable color scheme
- Variable zoom and focus renders
- Outputing to .png
- Animating to .gif
- Animation generation with linear or exponential zoom
- Stationary or moving focal point
- Render individual frames of zoom animation
- Bash script to render multiple frames in parallel, leverages multiple cores (tested up to 40 cores)
- Combine individual images of frames into animated .gif, variable delay between frames
See examples here! Images and animated gifs rendered on UoE Informatics computing servers.
The following third party libraries/packages are required for low level image manipulation
JuicyPixels is the library used to draw output into image files.
cabal update cabal install juicypixels
colour (not color!) package is used to represent colors as well as switching between colorspaces.
cabal update cabal install colour
Note: It is important to run commands from project root to ensure relative file paths are correct.
You may need to chmod +x
executables and shell script in order to run them.
There are 2 ways of generating animated images.
-
Generate entire .gif at once
- Use
createGifColor
function provided inImageOutput
function, by passing a list ofImage
createGifColor [createImage size (drawColorZoom i (-0.75,0)) | i <- [1..10]]
- Not recommended for high resolutions or high frame count (takes a while)
- Use
-
Generate individual frames then combine them 0.
cd
to root of project folder- Modify
src/generateFrames.sh
to change number of desired frames - Modify
src/generateFrame.hs
to change pixel rendering function - Compile
src/generateFrame.hs
withghc -O2 -isrc -outputdir tmp -o generateFrame src/generateFrame.hs
- Run
./generateFrames.sh
Warning: very CPU intensive operation - Grab a coffee, it's gonna be a while
- Edit
src/imagesToGif.hs
to change number of frames - Compile
src/imagesToGif.hs
withghc -O2 -isrc -outputdir tmp -o imagesToGif src/imagesToGif.hs
- Run
./imagesToGif
- Grab another coffee, it'll be done by the time you're back
- Marvel at the gif animation while sipping coffee
- Modify
The second method is preferred and much faster as it renders all frames concurrently, leveraging all CPU cores.
Examples are provided in src/generateStatic.hs
for drawing a few sample fractals,
modify source to add your own render functions.
cd
to root of project folder- Compile
src/generateStatic.hs
withghc -O2 -isrc -outputdir tmp -o imagesToGif src/generateStatic.hs
- Run
./generateStatic i
wherei
is number for fractal as defined in source.
While individual haskell source files can be run in GHCi, it is not recommended due to poorer performance.
Run ghci -isrc src/filename.hs
from project root for interactive environment.
- Write more documentation
- Generate more example outputs
- Rewrite functions to make changing parameters easier
- Optimizations to reduce runtime