Fractal Image Generator
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.
Generating animated images
There are 2 ways of generating animated images.
Generate entire .gif at once
createGifColorfunction provided in
ImageOutputfunction, by passing a list of
createGifColor [createImage size (drawColorZoom i (-0.75,0)) | i <- [1..10]]
- Not recommended for high resolutions or high frame count (takes a while)
Generate individual frames then combine them 0.
cdto root of project folder
src/generateFrames.shto change number of desired frames
src/generateFrame.hsto change pixel rendering function
ghc -O2 -isrc -outputdir tmp -o generateFrame src/generateFrame.hs
./generateFrames.shWarning: very CPU intensive operation
- Grab a coffee, it's gonna be a while
src/imagesToGif.hsto change number of frames
ghc -O2 -isrc -outputdir tmp -o imagesToGif src/imagesToGif.hs
- Grab another coffee, it'll be done by the time you're back
- Marvel at the gif animation while sipping coffee
The second method is preferred and much faster as it renders all frames concurrently, leveraging all CPU cores.
Generating static images
Examples are provided in
src/generateStatic.hs for drawing a few sample fractals,
modify source to add your own render functions.
cdto root of project folder
ghc -O2 -isrc -outputdir tmp -o imagesToGif src/generateStatic.hs
iis number for fractal as defined in source.
Running in interactive mode
While individual haskell source files can be run in GHCi, it is not recommended due to poorer performance.
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