s_fractal_cpp is a Mandelbrot and Julia fractals generator written in C++.
The generation parameters are specified in an XML file. The generated images are in TGA format.
Image below was generated with s_fractal_cpp.
In 2004, s_fractal_cpp was originally compiled on Windows XP with Visual Studio 2003, but it was portable C++. It now just requires a WSL (Windows Subsystem for Linux) or a Linux shell with CMake and libxml2 installed.
To install WSL on Windows 10, read the Installation Guide.
For a quick use of a Linux shell, Visual Studio Online is a perfect solution. It was used to test compilation of s_fractal_cpp.
sudo apt-get install libxml2
sudo apt-get install cmake
After cloning this repo, compilation is made with cmake and make.
cmake -Bbuild -H.
cd build/
make
The image below is a screen capture of the compilation in a Linux shell with Visual Studio Online.
Build files and CMake files are generated in 'build' folder. A 'bin' directory is created at root level. At this same level, there is a 'data' folder with a fractal.xml file. This file contains the parameters for generation of Mandelbrot and Julia fractals. fractal.xml is the default filename used. This filename can be provided as first command line argmuent.
cd data/
../bin/s_fractal_cpp
../bin/s_fractal_cpp gen.xml
The image below is a screen capture of program running in Visual Studio Online.
Hereafter an example of an XML configuration file for s_fractal_cpp.
Root Node is 'Fractal', Followed by 'Scenario' which contains a sequence of 'Image'. 'Image' contains 'Type' and 'ParamsId'. After 'Scenario' definition, 'MandelbrotParams' and 'JuliaParams' are described.
NB: XML parsing is not very robust and errors are not always detected...
<?xml version="1.0" encoding="utf-8"?>
<Fractal>
<Scenario>
<Image id="1">
<Type>Mandelbrot</Type> <!-- Mandelbrot or Julia -->
<ParamsId>1</ParamsId> <!-- id of MandelbrotParams (see below) -->
</Image>
<Image id="2">
<Type>Julia</Type>
<ParamsId>1</ParamsId> <!-- id of JuliaParams (see below) -->
</Image>
</Scenario>
<MandelbrotParams id="1"> <!-- MandelbrotParams id #1 -->
<width>600</width> <!-- output image size -->
<height>600</height>
<maxIterations>100</maxIterations> <!-- maxIterations is used to compute the step -->
<minC>
<real>0.25</real> <!-- min value for C -->
<imag>0.25</imag>
</minC>
<maxC>
<real>0.65</real> <!-- max value for C -->
<imag>0.65</imag>
</maxC>
<minColor> <!-- RGB color definition -->
<red>0</red>
<green>64</green>
<blue>64</blue>
</minColor>
<maxColor> <!-- RGB color definition -->
<red>255</red>
<green>225</green>
<blue>255</blue>
</maxColor>
<outputFile>mandelbrot12.tga</outputFile> <!-- output filename -->
</MandelbrotParams>
<JuliaParams id="1"> <!-- JuliaParams id #1 -->
<width>150</width> <!-- output image size -->
<height>150</height>
<maxIterations>50</maxIterations> <!-- maxIterations is used to compute the step -->
<minZ> <!-- min value for Z -->
<real>-0.5</real>
<imag>-0.5</imag>
</minZ>
<maxZ> <!-- max value for Z -->
<real>0.5</real>
<imag>0.5</imag>
</maxZ>
<c> <!-- value for C -->
<real>0.5</real>
<imag>0.5</imag>
</c>
<minColor> <!-- RGB color definition -->
<red>0</red>
<green>0</green>
<blue>0</blue>
</minColor>
<maxColor> <!-- RGB color definition -->
<red>255</red>
<green>255</green>
<blue>255</blue>
</maxColor>
<outputFile>julia23.tga</outputFile> <!-- output filename -->
</JuliaParams>
</Fractal>
A pseudo-code description of the Mandelbrot algorithm used by s_fractal_cpp is detailed hereafter. For a complete description of Mandelbrot set, refer to the Wikipedia article.
Let
Let
if
Let a complex number. depends on the coordinates of the pixel.
A pseudo-code description of the Julia algorithm used by s_fractal_cpp is detailed hereafter. For a complete description of Julia set, refer to the Wikipedia article.
Let
if
Let and complex numbers. depends on the coordinates of the pixel. is a constant.
This code was developed in 2004 and was part of an ambitious (and immodest) side project named Sofia. It intended to be a way for developing knowledge.
Its immodest introduction motto was (in french):
Dans la seconde moitié du Ve siècle avant JC, les sophistes firent profession d'enseigner la sofia, c'est à dire tout ce qui rend l'homme plus habile, plus savant, plus vertueux. Philosophes, ils étudiaient la logique, les phénomènes célestes, remettant en question les idées reçues, éveillant les intelligences.
Which is translated in:
In the second half of the 5th century BC, sophists made a profession of teaching sofia, that is, all that makes man more skilful, more learned, more virtuous. Philosophers, they studied logic, celestial phenomena, questioning conventional wisdom, awakening intelligences.
Unconsciously and unrelatedly, Sofia is also the name of my beloved daughter, born in 2015.
If you want to contact me you can reach me at ludorg@ludorg.net.
This project uses the following license: MIT.