percolation

This commit is contained in:
John Gatward
2026-03-17 15:48:13 +00:00
parent 6bef2094cb
commit c50e97987b
19 changed files with 10570 additions and 6 deletions

View File

@@ -0,0 +1,73 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Percolation</title>
<link rel="stylesheet" href="style.css"/>
</head>
<body>
<div class="container">
<a href="/#projects" class="back-button">← Back</a>
<header>
<h1>Percolation</h1>
<p class="subtitle">A simulation written in C &amp; Raylib.</p>
</header>
<section>
<p>
<strong>Percolation</strong> is a simple model for connectivity on a grid. Each cell is either open or closed.
This simulation stops as soon as there is a path from the top of the grid to the bottom through the open cells.
</p>
<div class="info-box">
<p>
In this simulation, cells are randomly opened on a grid. Percolation occurs when there exists
a connected path of open cells from the top to the bottom of the grid. It is a neat way to visualise
threshold behaviour: below a certain probability nothing connects, and above it large connected regions
suddenly begin to appear.
</p>
</div>
</section>
<div class="canvas-container">
<div class="canvas-toolbar">
<p>Canvas</p>
<button id="fullscreenButton" class="action-button" type="button">Fullscreen</button>
</div>
<div class="canvas-shell">
<canvas id="canvas" aria-label="Percolation simulation canvas" oncontextmenu="event.preventDefault()"></canvas>
</div>
<div id="status" class="status">Downloading...</div>
<progress id="progress" value="0" max="100" hidden></progress>
<details>
<summary>Show console output</summary>
<label class="visually-hidden" for="output">Console output</label>
<textarea id="output" rows="8" readonly></textarea>
</details>
</div>
<section>
<h3>Technical Details</h3>
<p>
The simulation uses a <strong>disjoint-set (Union-Find)</strong> style connectivity algorithm. As random cells open,
each open cell is union-ed with its open neighbours, and two virtual nodes represent the top and bottom edges
of the grid. Percolation is detected the moment those two virtual nodes become connected.
</p>
<p>
This makes each update fast and scalable even for larger grids.
</p>
</section>
<footer>
<p>Built with C, Raylib, and WebAssembly</p>
</footer>
</div>
<script src="script.js"></script>
<script async src="index.js"></script>
</body>
</html>