Skip to content

Instantly share code, notes, and snippets.

@4hg
Created May 4, 2022 15:02
Show Gist options
  • Save 4hg/2b3497365d194f69a02297ce6470bd1f to your computer and use it in GitHub Desktop.
Save 4hg/2b3497365d194f69a02297ce6470bd1f to your computer and use it in GitHub Desktop.
1D Totalistic Cellular Automata code written for my writeup on the subject.
require 'viewmat'
NB. rules are base-4, but the base is dependent on the number of states
NB. output is 500x500
NB. colors are encoded as hex
NB. r - 0 for custom rule, 1 for random rule
NB. s - 0 for single 1-cell start, 1 for random start
NB. c - 0 for custom colors, 1 for random colors
NB. g - iter function
NB. edit these to change modes
'rm sm cm' =: 0 0 0
r =: rm { (301979 #:~ 10 # 4) ,: (10#4) #: ? 1048575
s =: sm { (1 (<250) } 500 $ 0) ,: ? 500 $ 3
c =: cm { (16b444444 16b808080 16bff0000 16b000000) ,: ? 4 $ 16bffffff
g =: {{ r {~ +/ > |.&y each 1 0 _1 }}
viewrgb c {~ g^:(<500) s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment