Magnetic JavaScript

A material becomes magnetized when a majority of its atomic spins line up in parallel. Iron and a few other substances (ferromagnets) spontaneously magnetize, but only below a threshold temperature. Here the two possible spin directions are represented by different colors. At high temperature they mix randomly, but with cooling large blocks of uniform color begin to appear. (Inspired by code by Dan Schroeder, Weber State University.)

Download source code.