Fractal generator

Introduction

I needed something small to generate pretty pictures with my netpbm module. As evaluations of pixel colours in fractals are independent of each other, the time to generate a picture can be reduced significantly by spreading the calculation over multiple cpu cores. This is achieved with OpenMP.

Both Mandelbrot and Julia fractals (or parts thereof) can be generated pretty quick (for a command-line application at least).

Command Line Options

By default, the program will create a low resolution version of the above Mandelbrot fractal.

To change the output, supply the program with other command line options. All options can be viewed as follows:

./test_fractals -h

Usage: ./test_fractals [options]

options:

--iter-limit, -L
set the iteration limit
[integer] default: 250

--fname-mandel, -m
set the file name for the mandelbrot fractal
[character] default: mandel_1.ppm

--fname-julia, -j
set the file name for the julia fractal
[character] default: julia_1.ppm

--help, -h
print help message to screen and quit
[logical] default: F

--im-width, -W
set width in pixels of the image
[integer] default: 600

--im-height, -H
set height in pixels of the image
[integer] default: 400

--julia, -J
create julia fractal
[logical] default: T

--mandelbrot, -M
create mandelbrot fractal
[logical] default: F

--area-width, -x
set width of the area to render
[real_dp] default: 4.00000000000000

--area-height, -y
set height of the area to render
[real_dp] default: 2.00000000000000
--area-centre, -c
set centre of area to render
[complex_dp] default: (0.000000000000000E+000,0.000000000000000E+000)

--x-parts, -X
set number of x-parts to divide image in
[integer] default: 4

--y-parts, -Y
set number of y-parts to divide image in
[integer] default: 4

--colourband, -b
set default colourband xml file
[character] default: ../../../data/colorband.001.xml

Instructions for obtaining the sources and building the test program are given below.

Colorband

The colorband can be created from within Blender using this Python script. Alternatively, download the complete blend file with an example in it from here. The xml file for the colorband shown in the following screenshot can be found here.

Sources

The main module is a bit more difficult to compile, as it depends upon the FoX XML library by Tony White. Version 4.0.1 is known to compile with g95 and ifort, you can download it here.

The module and a test program can be downloaded here as a compressed tar archive. This archive does not contain build files, but using ifort, the module library and program can be build as follows:

wget http://users.telenet.be/tuinbels/fortran/m_fractals-2.0.tgz
tar -xzf m_fractals-2.0.tgz
cd m_fractals/
ifort -c -o m_precision.o m_precision.F90
ifort -c -o m_sys_fun.o m_sys_fun.f90
ifort -c -o m_math_fun.o m_math_fun.f90
ifort -c -o m_option_parser.o m_option_parser.F90
ifort -c -o m_netpbm.o m_netpbm.f90

At this point, you have to download and compile FoX:

wget http://www.uszla.me.uk/FoX/source/FoX-4.0.1.tar.gz
tar -xzf FoX-4.0.1.tar.gz
cd FoX-4.0.1/
./configure FC=ifort
make
cd ../

Now, you can compile the last module (m_fractals.F90) and its program (test_fractals.f90) as,

ifort -c -o m_fractals.o -I./FoX-4.0.1/objs/finclude m_fractals.F90
ifort -c -o test_fractals.o -I./FoX-4.0.1/objs/finclude test_fractals.f90
ifort -o test_fractals -fPIC test_fractals.o -i_dynamic m_precision.o m_sys_fun.o m_math_fun.o m_netpbm.o m_option_parser.o m_fractals.o -openmp ./FoX-4.0.1/objs/lib/libFoX_dom.a ./FoX-4.0.1/objs/lib/libFoX_wxml.a ./FoX-4.0.1/objs/lib/libFoX_sax.a ./FoX-4.0.1/objs/lib/libFoX_common.a ./FoX-4.0.1/objs/lib/libFoX_utils.a ./FoX-4.0.1/objs/lib/libfsys.a ./FoX-4.0.1/objs/lib/libFoX_utils.a

As a last step, download the sample colourband xml-file and run the test program:

wget http://users.telenet.be/tuinbels/scripts/colorband002.xml
./test_fractals -b colorband002.xml -J F -M -L 1000 -x 3 -y 2 -c "(-.5,0.)"

License

The sources are licensed under a 3-clause BSD license.

Examples

The following 14 images show the structure of the mandelbrot set around the point (-0.743643887037151,0.131825904205330) at different zoom levels. Every image shows the centre of the area of the previous image with a magnification of 10. These were created with the double precision version of the test program. The quadruple precision program should only be used if you want to zoom in further, as it is an order of magnitude slower than the double precision version.