A fractal is a set with structure at every scale, and usually a dimension that is not an integer. The Mandelbrot and Julia sets come out of iterating , the strange attractors of chaos have the same kind of structure, and the dimension is the number that lets you compare them. Everything here is cheap to compute and shows up directly in shader work.

Zoom in and the edge keeps showing new detail forever. Rendered for this page.
Mental Model
- Escape-time fractals ask one question per pixel: does this orbit stay bounded, and if not, how fast does it leave?
- Mandelbrot varies with . Julia fixes and varies . Same formula, different slice.
- Smooth coloring removes the visible bands by turning the integer escape step into a continuous value.
- Dimension counts how the amount of detail grows as you shrink the ruler, .
1. Escape-Time Mandelbrot and Julia

Start at a point, square it and add c, again and again. Dark points stay close forever; coloured points escape, and the colour says how fast. Rendered from the equations on this page.
Iterate . A complex number is in the Mandelbrot set if the orbit from stays bounded. Once the orbit is certain to escape, so 2 is a safe escape radius. For a Julia set you fix (for example ) and ask the same question for every starting on the grid.
A few spot checks, with a cap of 100 iterations: , and never escape; escapes after 29 steps, after 11, after 2. Orbits near the boundary of the set take many steps to leave, and that is where all the detail is.
2. Smooth Coloring
Coloring by the integer step gives visible bands. Fix this by estimating where the orbit would have crossed the radius between steps. Once is large, squaring doubles its logarithm each step: . Solving gives the continuous iteration count
where is the first step with (the only shifts the scale). Use a large radius such as so the approximation holds. Feed into a palette.
import numpy as np
def mandelbrot(w=800, h=600, maxit=200, R=256.0):
x = np.linspace(-2.2, 0.8, w); y = np.linspace(-1.1, 1.1, h)
c = x[None, :] + 1j * y[:, None]
z = np.zeros_like(c); nu = np.zeros(c.shape); alive = np.ones(c.shape, bool)
for n in range(maxit):
z[alive] = z[alive] ** 2 + c[alive]
esc = alive & (np.abs(z) > R)
nu[esc] = n + 1 - np.log2(np.log(np.abs(z[esc])) / np.log(R))
alive &= ~esc
return nu # 0 inside the setFor a Julia image, start with z = c_grid and a constant c. In a fragment shader the loop is the same, one pixel per invocation.
3. Self-Similarity and Dimension

Every corner holds a smaller copy of the whole triangle, and each copy holds even smaller ones. Rendered from the equations on this page.
If a shape is made of copies of itself, each scaled by a factor , its similarity dimension is
The Sierpinski triangle is 3 copies at half size, so
A line gives , , ; a filled square gives , , . The triangle lies between them: it takes up more than a curve and has no area.
4. Box Counting
For shapes that are not exactly self-similar, cover the set with boxes of side , count the non-empty boxes , and fit
In practice you plot against over a range of box sizes and take the slope. I tested this on a 1024 by 1024 Sierpinski bitmask (pixel filled when i & j == 0). Counting boxes of side 1, 2, 4, …, 128 pixels gave 59049, 19683, 6561, …, 27 occupied boxes, a factor of 3 per halving, and the fitted slope is 1.585, matching .
Common mistake
Box counting only makes sense in the range between the pixel size and the image size, and over at least a decade or so of scales. Include the largest and smallest boxes and the slope drifts. For a point cloud from an attractor you also need enough points that small boxes are not empty by chance.
5. Dimensions of Things in This Garden
The boundary of the Mandelbrot set has dimension 2 (a result of Shishikura), as complicated as a curve in the plane can be. The Lorenz attractor has dimension of about 2.06, a little more than a surface, consistent with the Kaplan-Yorke estimate computed in Lyapunov Exponents. Treat 2.06 as approximate: estimates from correlation-dimension methods vary in the second decimal.
Related
- Strange Attractors Beyond Lorenz: fractal sets from ODEs and maps
- Lyapunov Exponents: the Kaplan-Yorke dimension
- The Logistic Map and Bifurcations: the real slice of the Mandelbrot set
- Noise Functions: fBm gives statistical rather than exact self-similarity
- Fragment Shader Basics: running the escape loop per pixel