I’m on day two of my attempt to spend an hour every day building something fun with code; Yesterday I looked at 2D cellular automata by building Conway’s Game of Life, today I’m going to stick to the theme but drop down a dimension to 1D and look at pattern generation by rendering elementary cellular automaton 🔗 using the Wolfram Code Rules 🔗.

“Wolfram code is a widely used numbering system for one-dimensional cellular automaton rules, introduced by Stephen Wolfram in a 1983 paper and popularized in his book A New Kind of Science.” (Wikipedia 🔗)

Each row on the horizontal axis is a generation of cells and the vertical axis shows each successive generation based on the rules.

There are 256 possible rules based on the fact there are 8 possible states that a cell and it’s neighbours could be in, and two possible results for each of those states (on or off). Not all of the rules give interesting results and some are inversions or reflections of other rules, but the variation is captivating, as is how patterns from nature jump out in some of them. Most the patterns do not actually repeat but they seem to make some intuitive sense to our brains. I’d love to see some of these woven or printed on fabric as giant non-repeating patterns.

The examples below are all generated live and if you reload the page you will get new patterns following the same rules.

Rule 30 - Random Starting Row
Rule 110 - Random Starting Row
Rule 150 - Random Starting Row
Rule 225 - Random Starting Row

The above examples all start from a row filled with random cells, the examples below are the same four rules but starting from a single live cell.

Rule 30 - Single Starting Cell
Rule 110 - Single Starting Cell
Rule 150 - Single Starting Cell
Rule 225 - Single Starting Cell

The potential uses of these rules are really interesting too. Some of the rules (like Rule 90) if started with a single live cell produce a Sierpiński triangle. Rule 30 when started with noise generates a pattern similar to some shells 🔗. Apparently Rule 184 can be used to model traffic flow and others are used to model the dispersal of gas.

The generator I built can render all the rules in the set, I think a good future daily-code could be to make an interface to allow people to interactively play with the different rules and starting conditions. If you have any ideas for things to play with on a daily code hour let me know.