At first glance, a music visualizer seems like a simple mapping tool: sound goes in, waves are plotted on screen. But if you look at the fluid, organic, and shifting patterns of ShoggothOx, you will realize that there is a deeper computational engine at work. The secret to these morphing visual textures lies in Cellular Automata (CA) — a branch of computer science and mathematical physics that simulates complex systems through simple, local interactions.
A cellular automaton consists of a regular grid of "cells," each of which resides in one of a finite number of states. The grid evolves through discrete timesteps. In each step, every cell determines its new state based on its current state and the states of its immediate neighbors, governed by a set of mathematical transition rules.
The most famous cellular automaton is John Conway's Game of Life (1970). It is a binary, discrete system:
Conway's Game of Life simulates biological systems. It displays emergent behaviors like "gliders" (oscillating structures that travel across the grid) and "glider guns" that create them, proving that complex, symbolic self-replication can emerge from a few simple rules.
While Conway's system simulates biology, ShoggothOx simulates physical thermodynamics and fluid dynamics. To achieve this, it replaces discrete, binary thresholds with a Continuous Cellular Automaton (CCA) framework:
ct+1 = max(0, ⌊ s / 4 ⌋ - 1)
Where s is the sum of selected neighbor cells.
The lookup-table bounds behind this equation are examined in Proving Pixel Math with Verus.
This formula is a discrete approximation of the physical heat equation:
∂u/∂t = α∇2u
The Laplacian operator (∇2) measures the difference between a point's value and the average value of its surrounding neighborhood (local spatial curvature). If a cell is brighter than its neighbors, the Laplacian is negative, causing it to cool down; if it is darker, it heats up.
Solving the continuous heat equation exactly requires expensive numerical integration. Instead, ShoggothOx approximates the Laplacian using a discrete finite-difference stencil (averaging neighboring pixels). This discrete approximation allows the engine to compute diffusion using simple, local array operations, which run extremely fast on both the CPU and GPU to maintain 60 FPS.
In physics, heat does not just diffuse; it also flows via convection. ShoggothOx models this by shifting the neighborhood convolution kernel. For example, in the Upward Flame mode, the cell at index i gathers neighbor values from the rows directly below it (at offsets +W-1, +W, +W+1, and +2W, where W is the row width).
Because each pixel draws its energy from below, the brightness appears to rise upward. This directional convolution, combined with the constant decay term (the -1 in the equation), creates the organic, rising, and fading trails of fire.
To combine convection with more complex movement (like spirals and zooms), ShoggothOx layers these drift stencils on top of precomputed warp tables.
By tweaking the convolution stencil and the decay rate, we can alter the visual "physics" of the simulation:
Historically, Cthugha was limited to small 160×100 grids because 90s CPUs had to compute these loops in raw assembly. ShoggothOx compiles native Rust to WebAssembly to perform audio processing, but it pushes the cellular simulation boundary into hardware-accelerated GPUs.
Using WebGPU and WebGL fragment shaders, ShoggothOx runs the neighbor stencil averages and coordinate warps directly on graphics hardware. The entire simulation grid is stored in GPU memory as a texture, allowing us to evaluate millions of cell transitions in parallel via compute shaders. What once required assembly optimization on a 486 PC now runs effortlessly at 60 FPS at native high-DPI monitor resolutions. For environments without hardware acceleration, ShoggothOx falls back to a highly optimized WebAssembly CPU path, executing the cellular transition loops in memory using flat 1D arrays and pointer swaps.