Each cell holds a spin s = ±1. Nearest-neighbour spins interact through H = −J·ΣSᵢSⱼ − H·ΣSᵢ. The Metropolis algorithm proposes random single-spin flips and accepts them with probability min(1, e^(−ΔE/kT)), which samples the correct thermal (Boltzmann) distribution at temperature T.
ΔE = 2·J·s·(sum of 4 neighbours) + 2·H·s
accept if ΔE ≤ 0, else accept with P = e^(−ΔE/T)
Below T_c the exchange term dominates and the lattice spontaneously orders (all red or all blue); above T_c thermal noise randomises it. The lower strip plots magnetisation M(t) over the last 200 sweeps.