Fractal Gallery

A collection of classic fractal programs in C++ with cross-platform SDL2 rendering

Classic Fractals

Sierpinski Triangle

Chaos-game point iteration converging to the Sierpinski gasket.

sierpinski/sierpinski.cpp
\( P_{n+1} = \frac{P_n + V_{rand}}{2} \)

Sierpinski Carpet

Recursive 9-subdivision with center square removed at each level.

sierpinski/sierpinskiCarpet.cpp
\( D = \frac{\ln 8}{\ln 3} \approx 1.893 \)

Koch Snowflake

Each line segment replaced by 4 segments forming an equilateral bump.

kochsnow/kochsnowByEasyX.cpp
\( D = \frac{\ln 4}{\ln 3} \approx 1.262 \)

Cantor Set

Remove the middle third of each segment, recursively.

cantor/cantor.cpp
\( D = \frac{\ln 2}{\ln 3} \approx 0.631 \)

Arborescent Tree

Recursive branching tree with brown-to-green gradient and random jitter.

arboresent/arboresent/arboresent.cpp
Branch: \( L_{n+1} = 0.72 \cdot L_n, \; \theta \pm 30° \)

Rainbow

HSL color gradient background with concentric rainbow arcs.

rainbow/rainbow.cpp

Starfield

Animated star particles scrolling with variable speeds.

stars/stars.cpp

New Fractals

Mandelbrot Set

Escape-time algorithm with 256-iteration rainbow palette.

mandelbrot/mandelbrot.cpp
\( z_{n+1} = z_n^2 + c, \quad |z| \leq 2 \)

Interactive Mandelbrot

Click to zoom 3x, press R to reset, Q to quit.

mandelbrot/interactive.cpp

Barnsley Fern

4 weighted affine transforms iterated 200,000 times.

fern/fern.cpp
\( \begin{pmatrix} x' \\ y' \end{pmatrix} = A_i \begin{pmatrix} x \\ y \end{pmatrix} + b_i \)

Dragon Curve

Paper-folding fractal built by recursive turn sequence.

dragon/dragon.cpp
\( D = 2 \) (plane-filling)

Hilbert Curve

Order-N space-filling curve with rainbow coloring.

hilbert/hilbert.cpp
Segments: \( 4^n - 1 \) for order \( n \)

L-System Interpreter

General L-system engine with turtle graphics. Demos: Koch, Dragon, Plant.

lsystem/demo.cpp
Axiom \(\xrightarrow{\text{rules}^n}\) turtle instructions: \( F, +, -, [, ] \)

Build

brew install sdl2          # macOS
cmake -B build -S .
cmake --build build
ctest --test-dir build     # run unit tests