STEP-BY-STEP CODE · THE BROWSER

How the interactive pages are made.

Students often ask how the boards, sliders and 3D views on this site work. The answer is shorter than it looks: a web page is a drawing that a small program redraws whenever something changes. These lessons build that program one part at a time, in plain JavaScript first and then with two libraries, and every page shows the exact code that is running on it.

I use the percolation board from the Hoshen–Kopelman lesson as the running example, so the physics is already familiar and we can concentrate on the interface. The cluster labeling is imported from that lesson's module rather than written again. Each page ends with a working interface that can be copied into another page under my code-use terms.

The lessons

What we need before starting

A text editor and a browser. Nothing is installed: the pages are ordinary HTML files with a <script type="module"> tag, and the two libraries are loaded from public content networks when a chart or 3D view scrolls into view. Readers who know Python will recognize most of the JavaScript; the differences that matter are pointed out where they arise.

Why plain JavaScript first

Most interactive figures on this site use no library at all. An SVG rectangle with a fill attribute is as easy to set as a NumPy array element, and a page that loads nothing extra opens instantly on a phone. I reach for Plotly when the reader needs hover readouts, zoom or export, and for three.js when there are tens of thousands of cubes to draw. The lessons follow the same order.