Playground
Lenia

A continuous Game of Life

Lenia Lenia was invented by Bert Chan. Like Conway's Game of Life it has cells and a rule, but the cell values are smooth numbers from 0 to 1, space and time are very fine, and the neighborhood is a ring. Stable creatures glide, turn and pulse over the field. Paper: Bert Chan (arXiv)

Relation to the Game of Life Game of Life counts eight neighbors and gives alive or dead. Lenia takes a weighted mean over a ring of radius R and nudges the cell up or down by a smooth amount. Back to the Game of Life

GPU ping-pong The field is a float texture. One fragment shader computes one step for every cell at once. It reads the old texture and writes a second one. Then both textures swap roles. Wikipedia

Original work

How it works

Every frame runs the chosen number of steps. Each step is one full-screen pass of a fragment shader over all cells.

  • Kernel: K(r) = (4 · r · (1 − r))⁴ for 0 < r < 1, else 0. Here r is the distance to the cell divided by the radius R. This is a smooth ring.
  • Potential: U = Σ K · A / Σ K, the weighted mean of all cells closer than R. The shader reads (2R + 1)² cells per cell, so a large R is slow.
  • Growth: G(U) = 2 · max(0, 1 − (U − μ)² / (9σ²))⁴ − 1. It is +1 at U = μ and is exactly −1 when U is 3σ or more away from μ.
  • Update: A = clamp(A + dt · G(U), 0, 1). The time step is dt = 1 / T, so a small dt gives a smoother and slower animation. The edges wrap around.
  • Mass: the metric Mass is the sum of all cell values. It is read back from the GPU once per second. A stable creature keeps its mass.

Source code:lenia.shader.tslenia-simulation.tslenia-seed.ts

Note Simplifications in this demo:

  • Only the classic single-channel Lenia with one ring and one growth peak. There is no kernel editor and no multi-channel mode.
  • The grid is 256 × 256 and wraps around at the edges (a torus). The creatures are copied from the file animals.json of Bert Chan. Large creatures need a bigger world than this one.
  • If the GPU has no float32 render textures, float16 is used. Small changes per step are lost then, so creatures can drift or die.
Kernel radius R
Growth center μ
Growth width σ
Time step dt
Steps per frame

Press and hold the mouse or a finger on the canvas to paint living cells. A creature preset sets R, μ, σ and dt, and places the creature in the middle.

Frames/s: 0Backend: –Grid: 256 × 256Steps/s: 0Mass: 0