Skip to content

Instantly share code, notes, and snippets.

@Potherca
Last active December 30, 2020 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Potherca/c37b144721a707d6115647ad0889fea3 to your computer and use it in GitHub Desktop.
Save Potherca/c37b144721a707d6115647ad0889fea3 to your computer and use it in GitHub Desktop.
Example JS code for https://tixy.land
// (t,i,x,y) =>
t // for every frame …
? i // for every cell …
? [
s = // neighbour counter (off-by-one)
1, 15, 16, 17 // positive neighbour offset
].map(
N =>
s += // count neighbours
O[i + N] + // positive offset
O[i - N] // negative offset
)
: N = [O = N] // swap old (O) and new (N) state
: i // first run
? N[i] = i < 82 // initial seed for cells
: N = [], // create array to keep state
N[i] = // set new state for cell
4 == s | // if is has three neighbours
O[i] & // or cell lives
3 == s // … and has two neighbours
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment