Skip to content

XWHQSJ/Fractal

Repository files navigation

Fractal

Cross-platform fractal programs in C++

C++ License: MIT Platform: macOS/Linux/Windows WASM

About

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.


Gallery


Mandelbrot Set

Barnsley Fern

Koch Snowflake

Sierpinski Triangle

Dragon Curve

Hilbert Curve

Sierpinski Carpet

Arborescent Tree

Cantor Set

Try in Browser

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

Download Prebuilt Binaries

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.


Gallery

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

New Fractals

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


Note on Mario2

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.


Cross-Platform Build

Prerequisites

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

Build

brew install sdl2          # macOS
cmake -B build -S .
cmake --build build

Tests

ctest --test-dir build --output-on-failure

10 unit tests covering Koch midpoint math, Mandelbrot escape counts, Sierpinski convergence, and L-system rule expansion.

WebAssembly Build (Emscripten)

# 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.


Architecture

  • 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.

References

License

MIT -- Copyright (c) 2019 XWHQSJ

About

EasyX for Fractal Programs

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors