Cross-platform fractal programs in C++
A collection of classic fractal and graphics programs implemented in C++. Originally built with EasyX (Windows), now cross-platform via an SDL2 compatibility layer. Also compiles to WebAssembly via Emscripten for in-browser demos.
![]() Mandelbrot Set |
![]() Barnsley Fern |
![]() Koch Snowflake |
![]() Sierpinski Triangle |
![]() Dragon Curve |
![]() Hilbert Curve |
![]() Sierpinski Carpet |
![]() Arborescent Tree |
![]() Cantor Set |
Live demos (after first gh-pages deploy): All demos + math gallery. Static gallery above.
| Demo | Live Link |
|---|---|
| Mandelbrot (Interactive) | Launch |
| Mandelbrot Set | Launch |
| Barnsley Fern | Launch |
| Dragon Curve | Launch |
| Hilbert Curve | Launch |
| Koch Snowflake | Launch |
| Sierpinski Triangle | Launch |
| Sierpinski Carpet | Launch |
| Starfield | Launch |
Prebuilt native binaries for Linux (x86_64) and macOS (ARM64) are available on the Releases page. Tag a version (git tag v1.0.0 && git push --tags) to trigger a release build.
| Fractal / Demo | Source | Description |
|---|---|---|
| Sierpinski Triangle | sierpinski/sierpinski.cpp |
Chaos-game Sierpinski triangle |
| Sierpinski Carpet | sierpinski/sierpinskiCarpet.cpp |
Recursive carpet fractal |
| Cantor Set | cantor/cantor.cpp |
Cantor set line fractal |
| Koch Snowflake (EasyX) | kochsnow/kochsnowByEasyX.cpp |
Koch snowflake |
| Koch Snowflake (ASCII) | kochsnow/kochsnowByASCII.cpp |
Koch snowflake as ASCII art |
| Arborescent Tree | arboresent/arboresent/arboresent.cpp |
Recursive branching tree with depth-gradient coloring |
| Triangle | triangle/triangle.cpp |
Triangle drawing demo |
| Stars | stars/stars.cpp |
Starfield visual effect |
| Rainbow | rainbow/rainbow.cpp |
Rainbow arc rendering |
| Mouse / Cursor Effect | mouse/mouse.cpp |
Mouse-driven cursor visual effect |
| Fractal | Source | Description |
|---|---|---|
| Mandelbrot Set | mandelbrot/mandelbrot.cpp |
Escape-time Mandelbrot with 256-color rainbow palette |
| Interactive Mandelbrot | mandelbrot/interactive.cpp |
Click-to-zoom Mandelbrot explorer (press R to reset) |
| Barnsley Fern | fern/fern.cpp |
4 weighted affine transforms, 200k iterations |
| Dragon Curve | dragon/dragon.cpp |
Recursive paper-folding curve |
| Hilbert Curve | hilbert/hilbert.cpp |
Order-5 space-filling curve |
| L-System Interpreter | lsystem/demo.cpp |
General L-system engine with Koch, Dragon, Plant demos |
HTML Gallery with math formulas
The Mario2/ directory contains a separate small Mario-style platformer game built with EasyX. It is not a fractal program but is included as bonus content.
| Platform | Install SDL2 |
|---|---|
| macOS | brew install sdl2 |
| Ubuntu/Debian | sudo apt install libsdl2-dev |
| Fedora | sudo dnf install SDL2-devel |
| Windows | Use native EasyX, or install SDL2 and pass -DEASYX_COMPAT_USE_SDL=ON |
brew install sdl2 # macOS
cmake -B build -S .
cmake --build buildctest --test-dir build --output-on-failure10 unit tests covering Koch midpoint math, Mandelbrot escape counts, Sierpinski convergence, and L-system rule expansion.
# Install Emscripten SDK (if not already)
# See https://emscripten.org/docs/getting_started/downloads.html
emcmake cmake -B build-web -S . -DEASYX_COMPAT_USE_SDL=ON
emmake cmake --build build-web -j
# Each demo produces a .html + .js + .wasm triplet in build-web/The GitHub Pages deployment happens automatically on push to master via the gh-pages workflow.
easyx_compat.h-- Single-header SDL2 shim implementing the EasyX API subset used by all demos. On Windows with real EasyX installed, it's a no-op.fractal_common.h-- Shared boilerplate: RNG init, random/palette color helpers, standard window dimensions.lsystem/lsystem.h-- Reusable L-system interpreter with turtle graphics renderer.CMakeLists.txt-- Top-level build with per-demo targets and GoogleTest integration.
MIT -- Copyright (c) 2019 XWHQSJ








