Simply clone the repository and you are ready to go.
git clone https://github.com/VTrelat/Fractals.git
The following sections detail how the C program should be compiled and used in command line mode. If you want to use the graphical interface (user friendly), directly skip to section 3. Python GUI. However, I recommend reading the examples to understand how the generation works and what equations refer to.
This program makes use of the OpenMP library. To compile it, you need to have the OpenMP library installed on your system. If you are using GCC, just make sure to have GCC 4.9 or higher.
gcc --version
Then, you can compile the program using the following command:
gcc -O3 -fopenmp -o fractals parallel.c
Note: the
O3
flag is optional. It enables the compiler to optimize the code. It is recommended to use it, but depending on the versions of GCC, usingfopenmp
will set the optimization level toO3
by default.
Before compiling, you may want to change the equation used to generate the fractal. To do so, you need to modify the values for x1
and y1
in the function iterate
in parallel.c
:
unsigned int iterate(...)
{
...
while (iterations < max_iterations)
{
x1 = // your equation for x1
y1 = // your equation for y1
...
}
...
}
Variable x1
(resp. y1
) represents the real (resp. imaginary) part of the complex number for the next iteration. For instance, for the Mandelbrot set, the equation is
x1 = x0 * x0 - y0 * y0 + c0x;
y1 = 2 * x0 * y0 + c0y;
The program has 7 flags:
zoom
: float, the zoom level (default:1.0
)c0x
: float, the initial x coordinate of the center of the image (default:0.0
)c0y
: float, the initial y coordinate of the center of the image (default:0.0
)width
: int, the width of the image (default:1000
)height
: int, the height of the image (default:1000
)clipping
: int, the maximal modulus from the origin to be considered in the set (default:2.0
)filename
: str, name for the output image (default:out.ppm
)
Usage: ./fractal [-z zoom] [-x c0x] [-y c0y] [-w width] [-h height] [-c clipping] [-o filename]
The recursive equation used to generate the Mandelbrot set is:
where
Recall that we can define two sequences
It can be shown that any number in the Mandelbrot set is bounded by a modulus of
With the following command:
./fractal -z 1.0 -x 0.0 -y 0.0 -w 1000 -h 1000 -c 2.0
or
./fractal
We obtain the following image:
Julia Island is part of the Mandelbrot set (and thus is generated from the same equation). It can be obtained with the following command:
./fractal -z 0.00000011 -x -1.76877883 -y -0.00173891 -w 2000
We obtain the following image:
The recursive equation used to generate the Burning Ship fractal is:
where
From this, we define two sequences
It can also be shown that any number in the set is bounded by a modulus of
With the following command:
./fractal -z 0.025 -w -1.7 -h -0.04 -w 2000 -c 4.0
We obtain the following image:
Lately, I also developed a GUI (Graphical User Interface) for this program. It is made in Python with the Tkinter and Pillow libraries. To use it, you need to have Python 3 installed on your system as well as the Pillow library.
python3 -m pip install Pillow
Then, you can run the GUI with the following command:
python3 GUI.py
A similar window should appear:
- it runs the C parallel program for the fractal generation (so it is fast)
- resizable window (the image will be resized accordingly)
- it is especially helpful for quickly zooming in on a specific part of the fractal (smaller images render faster)
- zoom in/out with the mouse wheel
- if you are lost, simply go to
Image > Reset
- render an image with
File > Render
- a window will appear to choose the size of the image and a popup will appear when the image is rendered
- change the equation used to generate the fractal with
Image > Equation
- a window will appear to choose the equation
- you will be asked to enter the equation for
$x$ and$y$ in terms ofx
,y
,c0x
andc0y
where$x = Re(z)$ ,$y = Im(z)$ ,$c_x = Re(c)$ and$c_y = Im(c)$
- C code can be compiled / run separately with
File > Compile
andFile > Run
(with default values)