Wave 31: Newton's Fractal, Sand Pile & Complex Functions

Wave 31 brings three visually spectacular mathematics simulations: fractal basin boundaries from Newton's root-finding method, emergent power-law criticality in a grain-by-grain sand pile, and the kaleidoscopic domain colouring of complex functions. All three ship with full EN + UK pages.

Platform Numbers

466
Simulations
72
Categories
51
Devlogs
31
Waves

Wave 31 Simulations

🌀

Newton's Fractal

Newton's root-finding method applied to zn−1 in the complex plane. Each pixel is coloured by which root it converges to and how fast.

Open →

Sand Pile Model

Bak–Tang–Wiesenfeld self-organised criticality. Drop grains until cells topple; avalanches of all sizes appear with no parameter tuning.

Open →
🎨

Complex Functions

Domain colouring of f(z): hue = arg f(z), brightness = |f(z)|. Visualise poles, zeros, and branch cuts for 12 classic functions.

Open →

🌀 Newton's Fractal

The Algorithm

Newton's method finds roots of f(z) = 0 by iterating:

zn+1 = zn − f(zn) / f′(zn)

For the polynomial f(z) = zk−1, the roots are the k-th roots of unity: e2πin/k for n = 0, 1, …, k−1. The fractal arises because the boundaries between basins of attraction — the sets of starting points that converge to each root — are infinitely detailed.

Per-Pixel Rendering

Each of the 600×600 canvas pixels maps to a point z in the complex plane. The inner loop runs Newton steps until either the distance to the nearest root drops below a tolerance ε, or the maximum iteration count is reached. The convergence speed (iteration count when tolerance is met) modulates the brightness, producing the shaded gradient that makes the image three-dimensional in feel.

Complex Arithmetic

All arithmetic is done in real/imaginary component pairs. cmul(ar,ai,br,bi) returns [ar·br−ai·bi, ar·bi+ai·br]. zn is computed by repeated cmul rather than De Moivre (keeping the code branchless for any integer exponent). The division f(z)/f′(z) uses cdiv with the standard conjugate-over-magnitude² formula.

What to Try

⏳ Sand Pile Model

Bak–Tang–Wiesenfeld (1987)

The BTW sand pile is the canonical model of self-organised criticality (SOC). An integer height hi,j is stored at each cell of an N×N grid. Adding a grain to any cell may trigger a cascade of topplings according to the rule:

if h[i,j] ≥ K: h[i,j] −= K; each of 4 neighbours: h += 1

Grains that leave the boundary vanish (open boundary), so the total grain count is conserved on average. The system self-organises to a critical state without any tuning of K, and the distribution of avalanche sizes P(s) follows a power law P(s) ~ s−τ with τ ≈ 1.2.

Implementation

The grid is a flat Int32Array(N×N). The stabilise loop uses a BFS queue approach: cells that are critical at the start of a drop are seeded into the queue, then processed one by one. Newly critical neighbours are appended. Avalanche size is the total number of topple events. Colours are assigned per integer height (0=black, 1=dark green, 2=yellow-green, 3=amber, ≥K=red-orange) and written directly to a ImageData buffer.

What to Try

🎨 Complex Functions

Domain Colouring

Domain colouring is a technique for visualising complex-valued functions f : ℂ → ℂ on a 2D canvas. For every point z = x + iy in the viewing window, we compute f(z) = u + iv and map the result to a colour:

Complex Arithmetic in JS

All arithmetic is done analytically in (real, imag) pairs — no complex number objects are allocated to keep the inner loop fast:

Twelve functions ship in total. Switching function triggers a debounced re-render of all 360 000 pixels; a “Rendering…” overlay is shown during the ~30 ms computation.

What to Try

Technical Highlights

Tags

Newton's Method Fractals Basins of Attraction Sand Pile Self-Organised Criticality Power Law Complex Analysis Domain Coloring Conformal Mapping Wave 31

Wave 32 Preview

Three simulations are being designed for Wave 32:

All Wave 32 simulations will ship with EN + UK pages on launch day.