Spore

The tiny language every cell runs. Once per generation, each cell evaluates its program and the result decides whether it is alive (any truthy value) or dead (0, false, or nothing returned).

A first program

# Conway's Game of Life
if self {
  n in [2, 3]   # a live cell survives with 2 or 3 live neighbours
} else {
  n == 3        # a dead cell is born with exactly 3
}

A bare expression on its own line returns its value, so the block above is the same as writing return n in [2, 3]. The whole program fits in one line too: self ? n in [2, 3] : n == 3.

What a cell can see

NameMeaning
self, aliveThis cell's current state, 0 or 1.
nNumber of live cells among the 8 around this one (Moore neighbourhood).
vnLive cells among the 4 orthogonal neighbours (von Neumann neighbourhood).
N NE E SE S SW W NWEach individual neighbour, 0 or 1. North is up.
x, yThis cell's column and row, from the top-left corner.
w, hWidth and height of the grid.
tThe generation number, starting at 0.

Functions

count(r)Live cells within r steps (1–3), excluding this one. count(1) is n; count(2) looks at 24 cells.
cell(dx, dy)The state of the cell dx columns right and dy rows down (each −3…3).
random()A number in [0, 1). Deterministic: it depends on the cell, the generation and the seed.
chance(p)True with probability p.
min max abs floor round sqrt sin cos modThe usual maths. mod(a, b) is always non-negative.

Syntax

let d = abs(x - w / 2)      # declare a variable
d = d * 2                   # reassign it
if d < 10 and t % 20 < 10 {  # if / else if / else, with braces
  return 1
} else if n > 4 {
  return 0
}
n in 2..3                   # ranges are inclusive

Many programs in one grid

An automaton can hold up to eight programs. In the editor, pick a program as your brush and paint it onto cells. Each cell runs its own program, but all of them read the same shared states, so different “cultures” interact where they meet.

Edges and connections

Each edge of an automaton has a mode used when nothing is connected there:

voidBeyond the edge everything is dead.
solidBeyond the edge everything is alive.
wrapThe grid continues from the opposite edge (a torus, if all four wrap).
mirrorThe cells next to the edge are reflected back.

You can also connect an edge to the matching edge of another automaton, as long as both edges have the same length. Connected automata run in lockstep, so a glider can walk from one into the next. There are two kinds of connection:

One-wayYour edge reads theirs; they are not affected. Works with any public automaton, and any number of automata can read the same edge.
Two-wayBoth edges read each other. The other automaton must be yours or have open borders, and its edge must be free.

When you view an automaton, everything upstream of it (what it reads from, what those read from, and so on) is simulated too, so its history is the same for everyone. On the home page, neighbouring tiles in the garden connect two-way automatically when both have open borders and matching edges.

Determinism

Simulation runs entirely in your browser. Because programs, the seed and the initial state fully determine the history, everyone who opens an automaton sees the same story unfold.

Open the editor