How it works
Atoms from one smooth field
The simulation does not track atoms. It tracks a single smooth quantity, ψ: how much material there is at each point, averaged over a short time. In a liquid ψ is the same everywhere. In a crystal it piles up into regular peaks, and each peak is an atom. This is the phase-field crystal model of Elder and colleagues [1][2]: atomic detail, but on the slow time scale of diffusion, so a crystal can be watched growing.
The one equation
The outer ∇² means material only flows from place to place; it is never made or destroyed, so the average of ψ never changes. The (1 + ∇²)² term rewards ripples of one particular wavelength, which sets the distance between atoms. The ψ³ term keeps the peaks from growing without limit. In two dimensions the arrangement that wins is a hexagonal lattice.
Temperature and amount of material
The two physics sliders are the model's two numbers. Temperature is r: the more negative, the colder, and the stronger the pull to crystallise. Amount of material is ψ̄, the average density. Together they decide what the box ends up as: all liquid, crystals in liquid, or crystal everywhere. Cold enough for the amount of material (|ψ̄| below √(−r/3)), the liquid itself is unstable and crystallises on its own; just short of that it holds, and needs a seed to start.
Because material is conserved, a crystal grows by drawing in material from the liquid around it, which thins that liquid out. That is why a lone crystal slows down and stops, and why two crystals only press together when there is enough material to go round.
Seeds and tilt
A click stamps in a small patch of perfect hexagonal crystal, turned by some angle. The cold liquid next to it copies the pattern, so the whole crystal keeps that angle, its tilt, as it grows. A hexagon looks the same turned by 60°, so tilts run from 0 to 60°.
Grain boundaries and misfits
Each crystal is a grain. Where two grains with different tilts meet, their rows of atoms cannot line up, and the seam between them is a grain boundary, the same thing that shows up on a polished and etched piece of metal. To find them, each atom's neighbours are counted and the directions to them averaged (the bond-orientational order of Steinhardt, Nelson and Ronchetti [3]). Atoms without exactly six neighbours are the misfits, and they glow. Atoms on a crystal's outer edge also have fewer than six, but all on one side; those are a surface, not misfits, and do not glow.
Sheen and rainbow
Sheen imitates turning a piece of metal in the light: a grain glints when its rows line up with the light. The light stays put unless you turn the view, or tick the box that sweeps it round. A grain's tilt can still drift a little: a small grain squeezed between larger ones slowly rotates to fit them better, as grains in real metals do. Rainbow gives each tilt its own colour instead.
How it is solved
The box wraps round at its edges. Each step goes into Fourier space, where ∇² is just multiplication, and treats the stiff linear part implicitly so the step can be large; the cubic part is taken from the step before. One step on a 256 × 256 grid takes a few milliseconds in WebAssembly. The 3D view is the same flat field drawn as a landscape: height is ψ, lit from one side.
References
[1] K. R. Elder, M. Katakowski, M. Haataja and M. Grant, Modeling elasticity in crystal growth, Phys. Rev. Lett. 88, 245701 (2002).
[2] K. R. Elder and M. Grant, Modeling elastic and plastic deformations in nonequilibrium processing using phase field crystals, Phys. Rev. E 70, 051605 (2004).
[3] P. J. Steinhardt, D. R. Nelson and M. Ronchetti, Bond-orientational order in liquids and glasses, Phys. Rev. B 28, 784 (1983).
Recent open-source phase-field crystal codes: pyPFC (H. Hallberg et al., 2025) and OpenPFC (T. Pinomaa et al., 2024). This app is written from the equations in [1] and [2] and shares no code with them. More in the write-up.