Foundations
To those who are not familiar with cellular automata, here’s a guide to introduce you to Vivarium. For now just know that a vivarium is an abstraction we created to describe cellular automata in a way that is easy and fun to learn for those who wouldn’t know exactly where to start.
Vivarium
Section titled “Vivarium”In the digital world, think of a vivarium like a 2d image in motion. The movement happens in steps, each step is a consequence of the previous one. This motion is the result of a simulation driven by a set of rules that are unique to each vivarium. These rules are simple, but can create complex behaviors when combined together, making the image evolve over time. We’ll talk about rules in a bit. Now let’s define our building blocks.
Elements
Section titled “Elements”An element is an abstract way to represent anything we want to put in our vivarium. Dogs, cats, aliens, trees, sand, electricity, hot air balloons… are all valid elements. It’s up to you what an element represents. All is needed is:
- a name — like “alien” — to know what it is (how to distinguish it logically from other elements)
- a color — like “green” — to know how to draw it on the screen (how to distinguish it visually from other elements)
Neighborhood
Section titled “Neighborhood”Elements exists in a world we call the grid. Every element occupies a cell of the grid, and shares its surroundings with other elements. More than often, an element is influenced by its neighbors and evolve into another element when the configuration of its neighbors meets certain criteria. We call neighborhood the area of influence of a given element. Anything happening outside the neighborhood can be ignored, while anything that happens inside the neighborhood might have an impact on the element.
By default, the neighborhood of a cell is made of the 8 adjacent (diagonal included) cells surrounding it. In Vivarium, technically speaking, the central cell does not belong to its neighborhood.
Evolution
Section titled “Evolution”To understand how a vivarium evolves, let’s walk through a single step.
Imagine a tiny 5 by 5 grid. Every cell in the grid holds an element. Let’s say we have two elements: “space” (blue) and “alien” (green). Our starting grid is all blue except for one green cell right in the center.
Now let’s apply one rule: “a blue cell becomes green if it has exactly 1 green neighbor.”
The simulation processes this in two phases. First, it counts: for every cell in the grid, it counts how many green cells are in its neighborhood. The center cell is the only green cell, so only its immediate neighbors will get a count of 1. All other cells, being too far from the center, will get a count of 0.
Then, it updates: every cell that got a count of 1 becomes green. The rest stay as they are. After this step, the center cell is still green and all 8 of its neighbors have also turned green — forming a 3x3 green square in the middle of our grid.
Why two separate phases? Because if we updated cells one at a time as we scanned them, earlier updates would affect later counts. A cell might see some neighbors in their “new” state and others still in their “old” state, producing inconsistent results. By separating counting from updating, every cell makes its decision based on the same snapshot of the grid. This guarantees a fair, simultaneous evolution for every cell at every step.
A rule describes how a cell should change from one element to another. In its simplest form, a rule says: “every X becomes Y”. A rule can also have conditions — checks that must be satisfied before the transition happens.
When a vivarium is evaluated, each cell is checked against the rules of its element, in order. The first rule whose conditions pass is applied. If no rule passes, the cell stays unchanged.
Conditions
Section titled “Conditions”Conditions give rules their power. Without conditions, every cell of a given element would always change in the same way. Conditions let cells react to what is around them.
The most common condition is counting: check how many neighbors of a specific type surround the current cell. For example, “a dead cell becomes alive if exactly 3 of its neighbors are alive” is the famous birth rule from Game of Life.
Another condition is checking a specific neighbor: for example, “a cell becomes sand if the cell above it is sand.” This is useful for simulating gravity or flow.
A third condition is chance: a probabilistic check. “A tree catches fire with a 1 in 1000 chance.” This adds randomness and can create organic-looking patterns.
Rule priority
Section titled “Rule priority”When a cell has multiple rules, the order in which they are declared matters. Vivarium evaluates rules from top to bottom and picks the first rule that passes. Once a rule is accepted, no further rules are checked for that cell during that step.
This priority system is what lets you write “default” behaviors. You can place specific conditional rules first, and then a catch-all unconditional rule at the end as a fallback.
A kind is a way to group elements that share something in common. A kind doesn’t appear on the grid — it has no color. Instead, elements can extend a kind, meaning they inherit its properties.
Why is this useful? Imagine you have elements like wire, spark, and tail. They are all “conductors.” By creating a “conductor” kind and extending it with each of these elements, you can write a single rule that applies to all conductors, rather than writing the same rule three times.
The grid and wrapping
Section titled “The grid and wrapping”The grid is a two-dimensional array of cells. Each cell holds one element. When we say “the neighborhood of a cell,” we mean the cells that surround it. By default, Vivarium uses a square (Moore) neighborhood: the 8 cells that are directly adjacent, including diagonals.
What happens at the edges of the grid? By default cells at the border of the grid have missing neighbors. Positions that fall outside the grid are counted as empty, like a wall of nothingness that surrounds the world.
Alternatively we can make the grid wrap around — the top edge connects to the bottom, and the left edge connects to the right. This creates a toroidal surface (think of a donut). This way no cell is ever missing a neighbor.
Emergence
Section titled “Emergence”The most fascinating aspect of cellular automata is emergence. Simple rules, applied uniformly to every cell, can produce incredibly complex global behavior. Patterns move, grow, reproduce, and interact — all without any instruction telling them to do so.
Game of Life is a classic example: from just three rules, structures like gliders, oscillators, and even logic gates can emerge. This is what makes cellular automata a powerful tool for creative exploration and learning about complex systems.