A simulation written in C & Raylib.
Percolation 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.
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.
The simulation uses a disjoint-set (Union-Find) 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.
This makes each update fast and scalable even for larger grids.