An interactive, real-time web application simulating phase transitions and critical phenomena in the 2D Ising model using TypeScript, HTML 5 Canvas, and Chart.js.
The Ising Model is a foundational mathematical model of ferromagnetism in statistical mechanics. This project simulates a 2D square lattice of interacting magnetic spins (
- Real-Time Lattice Rendering: High-performance HTML5 Canvas rendering capable of handling high Monte Carlo step throughput at 60 FPS.
- Dual Simulation Engines:
- Metropolis-Hastings (Local Flips): Ideal for non-equilibrium dynamics, domain wall formation, and hysteresis loops.
- Wolff Cluster Algorithm (Global Flips): Drastically reduces critical slowing down near the critical temperature (
$T_{\rm c}$ ).- Note: With the Wolff algorithm, we have implement frame-skipping to reduce the "strobing" appearance of the lattice flips.
- Three Boundary Conditions: Swap dynamically between Periodic (bulk), Open (surface effects), and Fixed (+1 locked perimeter) boundary conditions.
- Synchronized Charting: Live updates for:
- Magnetization per spin (
$\langle M\rangle$ vs. Time). - Energy per spin (
$E$ vs. Time). - Dynamics hysteresis loop (
$\langle M\rangle$ vs.$H$ ) with time-faded trail opacity.
- Magnetization per spin (
- CVD-Accessible Theme: Designed with high contrast using dark slate and emerald teal to support users with color vision deficiencies.
- Interactive Control Panel: Adjust
$T$ ,$H$ ,$J$ , simulation speed, presents, or toggle auto-sweeps and pause/resume states.
The system is goverend by the 2D spin Hamiltonian:
Where:
-
$J$ is the spin-spin coupling constant ($J>0$ for ferromagnetism,$J<0$ for antiferromagnetism). - $\langle i,j\rangle denotes summation over nearest-neighbor lattice pairs.
-
$H$ is the external magnetic field.
In two dimensions, the model undergoes a second-order phase transition at Lars Onsager's critical temperature:
- Below
$T_{\rm c}$ ($T<T_{\rm c}$ ): Spontaneous symmetry breaking forms large aligned domains with non-zero net magnetization ($\langle M\rangle \neq 0$ ). - Above
$T_{\rm c}$ ($T>T_{\rm c}$ ): Thermal fluctuations dominate, destroying long-range order ($\langle M\rangle \rightarrow 0$ ).
For more information, see the blog post.
- Language: TypeScript
- Visualization: HTML 5 Canvas API & Chart.js
- Build Tool: Vite
- Typesetting: KaTeX
To keep single threaded JavaScript running at 60 FPS under heavy statistical sampling:
- Continguous Memory: Spins are mapped into a 1D
Int8Array (y * L + x)for optimal CPU cache locality. - Precomputed Boltzmann Factors: Acceptance probabilities for local energy changes (
$\Delta E \in {4J, 8J}$ ) are pre-calculated to avoid exepnsive runtimeMath.expcalls. - Decoupled Execution: Physics logic executes over dynamic MCS sub-loops white Canvas/Chart rendering is synchronized with borwser
requestAnimationFrame.
- Node.js (v18 or higher recommended).
npmorpnpm.
- Clone the repository:
git clone https://github.com/RandomKiddo/IsingModel.git
cd IsingModel- Install dependencies:
npm install- Start the local development server:
npm run dev- Open your browser and navigate to the
localhost, typicallyhttp://localhost:5173/IsingModel/orhttp://localhost:5173/.
To compile static producing assets:
npm run buildThe compiled bundle will be outputted to the dist/ folder.
This repository includes a pre-configured GitHub Actions workflow in .github/workflows/deploy.yml that automatically builds and deploys the Vite application to GitHub Pages whenever changes are pushed to master.
You can view the live deployment here.
Distributed under the MIT License. See LICENSE for details.
Copyright © 2026 RandomKiddo
This page was last edited on 08.06.2026.