A multithreaded Mandelbrot set viewer written in C++ using SFML.
- C++
- SFML 3
- CMake
cmake -S . -B build
cmake --build build
- Multithreading
- 10 Color themes
- Adjustable view
- Adjustable max iterations
| Control | Action |
|---|---|
| Left Click | Two clicks define a zoom rectangle |
| Right Click | Zoom out |
| C | Show controls |
| R | Reset view |
| F | Toggle fullscreen |
| T | Redraw and time current frame |
| Z | Undo first click |
| S | Correct aspect ratio |
| - / = | Decrease and increase max iterations |
| Arrow Keys | Move around |
| 1 to 0 | Change color scheme |
| ESC | Quit |
The core equation for the Mandelbrot set is:
However, in mandelbrot.cpp you don't see this equation directly in the code because of how complex numbers behave. Here is the derivation, starting with declaring precomputed variables. This is really only done for performance, since it avoids recomputing values:
The complex number
Or:
Calculate squares:
long double zr2 = zr * zr;
long double zi2 = zi * zi;Checking if
Check distance from origin:
Squaring both sides avoids sqrt() function:
Escape condition:
Square both sides for escape condition:
So:
if (zr2 + zi2 > 4.0) {
return i;
}Compute the next iteration:
Square
Expand:
The part
Distribute exponent for
Since
This naturally seperates the real and imaginary components:
Now we add
long double zi_new = 2.0 * zr * zi + ci;
zr = zr2 - zi2 + cr;
zi = zi_new;








