Skip to content

Instantly share code, notes, and snippets.

@JohnEarnest
Last active March 24, 2020 17:04
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 JohnEarnest/db734a06be7018ac18f2e233fdb4fc51 to your computer and use it in GitHub Desktop.
Save JohnEarnest/db734a06be7018ac18f2e233fdb4fc51 to your computer and use it in GitHub Desktop.
Sandpile Cellular Automaton
/ Sandpiles
/ see: https://www.youtube.com/watch?v=hBdJB-BzudU&t=0s
r: {y(#y)!x+!#y} / rotate y by x places
n: {+/(-1 1r\:x),(-1 1r/:\:x)} / orthogonal neighbor counts
t: {x+(-4*u)+1_+1_n@+0,+0,u:3<x} / toroidal sand collapsing
once: 100 100# 5 / initial board
tick: t / update: just collapse one iteration
draw: {,(;solarized;x)} / draw board as paletted pixels
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment