On this page
A desktop viewer for the Mandelbrot set that draws progressively on every CPU thread, with six colour schemes and PNG export.
Colored Samples
The mathematics
Each pixel is a point of the complex plane. Iterate
and count the steps until , after which the orbit must escape. A point that survives the iteration limit (250 at the start) is drawn black. The first view has side 2.5, centred on .
Shortcuts. The main cardioid and the period-2 disc never escape. With they are
Brent’s cycle test catches other interior points: once the orbit returns to within of its position at the last power-of-two step, it is on an attracting cycle.
Colouring
The bands scheme gives a point that escapes after steps the hue degrees, with saturation and value .
Smooth colouring. An escaping point is iterated to and gets
smooth(default): hue , a continuousbands.rainbow: the hue turns 8 degrees per step.fire,ice,grey: cyclic gradients with a period of 64, 64 and 32 steps.
Supersampling. With A or --samples N the last pass averages samples per pixel, at times the cost.
How a picture is drawn
- Up to three passes: one sample per 8 × 8 block, then every pixel, then the supersampled pixels.
- Each pass is cut into 32 × 32 tiles, from the centre outwards, that worker threads take one at a time.
- A drag, zoom or key drops waiting tiles; the old picture is moved and scaled at once.
Build and run
You need a C++17 compiler (GCC, Clang or MSVC) and CMake 3.25 or newer. CMake downloads and builds SFML 3.1.0.
sudo apt install cmake g++ libx11-dev libxrandr-dev libxcursor-dev libxi-dev libudev-dev libgl1-mesa-dev libfreetype-dev libharfbuzz-dev libfontconfig-dev fonts-dejavu-core
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build # the program and the tests
cmake --build build --target run # opens the window
ctest --test-dir build --output-on-failurexcode-select --install ; brew install cmake
cmake --preset default && cmake --build --preset default
./build/default/mandelbrotWith Visual Studio 2022 (“Desktop development with C++”):
cmake --preset msvc
cmake --build --preset msvc
ctest --preset msvc
build\msvc\Release\mandelbrot.exeWith MinGW-w64 use cmake -B build -G "MinGW Makefiles". SFML is linked statically, so mandelbrot.exe needs no DLLs.
- Switches:
-DMANDELBROT_BUILD_APP=OFFbuilds only the tested core (no SFML),-DMANDELBROT_BUILD_TESTS=OFFskips the tests,-DFETCHCONTENT_SOURCE_DIR_SFML=<checkout>builds offline. - Presets in
CMakePresets.json:default,debug,sanitize,core,core-sanitizeandmsvc. - On MSVC and Apple Silicon
long doubleis a plain 64-bitdouble, so the deepest zoom is about instead of .
Options and keys
./build/mandelbrot --view -0.7436,0.1318,0.002 --iterations 1000 --colours fire
./build/mandelbrot --render seahorse.png --size 1600x1600 --samples 3 --view -0.7436,0.1318,0.002
./build/mandelbrot --bench| Option | Meaning |
|---|---|
--size WxH | window size, 100 to 8192 each (default 600x600) |
--view RE,IM,SPAN | start view: centre and length of the shorter side |
--iterations N | iteration limit, 25 to 100000 (default 250) |
--colours NAME | bands, smooth (default), rainbow, fire, ice or grey |
--samples N | supersampling, 1 to 3 samples per pixel side |
--threads N | worker threads (default: one per hardware thread) |
--fullscreen, --no-system-font | start fullscreen; use the built-in pixel font |
--render FILE.png | draw one picture and exit, without a window |
--bench | time the renderer and exit |
| Key | Action |
|---|---|
| Click | Go to point (it becomes the centre) |
| Drag | Move the view; the picture follows the pointer |
| Scroll | Zoom in or out by 1.2x per notch about the cursor |
| W / S | Zoom in by 1.5x / out by 1.2x |
| Arrow Keys | Pan by 1/25 of the view |
| [ ] | 25 fewer / more iterations (at least 25) |
| C | Next colour scheme (Shift: previous) |
| A | Supersampling 1x1, 2x2, 3x3 |
| P | Save the picture as PNG |
| F | Fullscreen |
| O / H | Hide the overlay / show the list of keys |
| R | Reset view and iterations |
| Esc | Quit |
Zooming out stops at four times the first view. The overlay font is the file named by MANDELBROT_FONT, else a system monospace font, else a built-in pixel font.
Tests
The tests need no display: they compare the renderer with a plain loop (9,000 points, 1 to 8 threads).



