Re-posted from: https://cormullion.github.io/blog/2018/11/29/automata.html
To play along with this post, you’ll be able to find the source on github, and you’ll need Julia (version 1), and the packages Luxor, Colors, and ColorSchemes. This post was written using Fredrik Ekre’s Literate.jl.
I don’t need to give you any references—you’ll be spoilt for choice if you start googling.
Here in the UK we’re usually better at closing railway stations than opening new ones. Dr Beeching famously closed thousands of them (more than 50% of the total) in the 1960s. Occasionally, though, new stations are built, and one recent addition to the rail network is the station at Cambridge North, built mainly to serve the Cambridge Science Park. (I used to walk along the railway tracks there at weekends before the old disused line was re-opened, but that’s another story…)
When the station was opened, in 2017, there was a bit of chatter about the decorative panels used for the building.
(Image by cmglee at wikipedia, licensed CC-SA)
Thsee patterns were described by the designers at Atkins (the contractors) like this:
The station is wrapped in three equal bands of aluminium panels which have been perforated with a design derived from John Horton Conway’s “Game of Life” theories which he established while at Gonville and Caius College, Cambridge in 1970. These beautiful, delicate panels ensure passive security to ground floor glazed areas, assist with wayfinding while crossing the footbridge and allow the building to transform its appearance between day and night through sensitive backlighting.
This quote is from the original article (archived here), but it’s since been corrected, most probably in response to the anguished cries of thousands of Cambridge nerds who swiftly pointed out that, in fact, these patterns weren’t Life as we know it, but were actually one-dimensional cellular automata, and so linked, not so much with Cambridge’s John Horton Conway, as with noted Oxford/CalTech alumnus Stephen “Mr Mathematica” Wolfram.
I think the designers did a great job using these simple graphics to “create a harmonic relationship with the scientific research and industry of the Cambridge Colleges and nearby Science Park”.
So what is a one-dimensional cellular automaton?
A cellular automaton is a mathematical model that creates patterns automatically according to simple rules. In its simplest, one-dimensional form, it’s a row of empty squares, each of which can be occupied or empty. The rules for the model determine how sensitive the occupants of each square are to their immediate left and right neighbours, and whether, after some unspecified time, they survive or die. Sometimes empty squares can miraculously become occupied. Because a square has just two immediate neighbours, there are 8 different cases to consider, ranging from all empty (“□□□” or
000 in binary) to all full (“■■■” or
The rule determines how one generation changes to the next by specifying the outcome for each of the 8 cases. So, for example, an empty square surrounded by empty neighbours can continue to be empty (false, or 0), or it can produce a new occupant in the next generation, (true, or 1). There are 256 different combinations, since each of the 8 cases can be either 0 or 1.
The wikipedia has this nice animation showing how the rule produces the next generation of squares.
(Well, it has this nice animation now…)
To explore these simple automata, I started (1) by making a Julia structure:
cells array can hold trues or falses. The
colorstops array is eventually going to hold some color information. The middle cell is seeded with a single starter value.
binary_to_array() function just converts a binary number to a bit array (I suspect there’s a quicker way).
rules() function takes the values of an individual and its neighbours and applies the rule that determines its state for the next generation:
nextgeneration() function applies the rule to all the cells. I decided to make it wrap around, so that the final cell considers the first cell as one of its neighbours.
We’ll also teach Julia how to show an automaton in the terminal:
So now we can create a cellular automaton by providing a rule number (using the default of 100 cells):
update the automaton like this:
and show a historical diagram of its evolution:
The REPL display is more or less functional, but I want to play with the graphic output, so (you guessed):
You can call
nextgeneration() without displaying the results, of course. This lets you jump into the future history of an automaton at warp speed.
I found that sometimes drawing them from left to right looked better (like videos recorded on phones…?):
And now in color
So far I haven’t used the color information that’s stored.
nextgeneration() function can be updated with instructions about how to modify the color of the next generation, based on the current set of three cells.
draw() function can be adapted to make use of the color information. I decided to avoid tackling RGB color value transformations for a first pass, so the single value between 0 and 1 is used to select a color from a color map.
This could lead to hours of entertainment (depending on your definition of fun, of course). I uploaded a few experiments that didn’t turn out too badly on Flickr. The current rules show a kind of literal winning streak, as a cell that remains occupied for many generations ends up being brightly illuminated.
I think these images look quite good when scaled up. It only takes about a second to draw these, but would take much longer to stick them on the wall:
The rules for specifying a change in color could do with some kind of systematic definition, perhaps, such that, say, “rule C81” means “increase colorstop by amount if previous parent is 1, decrease it if previous uncle-aunt is 1”, and so on. Then you could pass a set of color rules to the drawing function. (uncle-aunt? I couldn’t find a word for something that is either an uncle or an aunt, but not a parent…)
Instead of drawing simple squares, it’s possible to draw other shapes. I’m quite fond of the squircle — you can change the
rt parameter to get different shapes:
(This SVG is quite big, and won’t display in Juno. But it should load in a browser.)
Getting around to it
It occurred to me that you could take a rectangular array and wrap it into a circle.
This shows all the rules in this circular form.
(Again, this image is quite demanding for SVG and can take a while to load, even though it doesn’t take long to generate.)
After playing with this idea, I thought it would make some nice jewellery:
This is rule 150. I mapped the array to a semicircle and drew it twice.
And it moves
Many of the rules have limited career paths. Some fizzle out very quickly, others settle down into a stable if repetitive life style. There are a few that continue to make patterns as the number of generations heads off into the thousands.
The unpredictable high achiever of the 1D cellular automata world is Rule 110. The rule itself is so simple, it could have been described in a Shakespeare play:
[Enter HAMLET, stage left.]
For Zeros become Ones at all positions,
Where the value to the right is One.
Yet Ones are changed to Zeros where’er
The values to left and right are One.
And yet this simple rule has been the subject of an astonishing amount of analysis, such as this in-depth paper by Martinez et al published in the wonderfully-named International Journal of Unconventional Computing. Matthew Cook’s famous paper proved that Rule 110 is capable of emulating the activity of a Turing machine.
I understood very little of those wonderful papers, but they did make me want to at least see Rule 110 in action, just in case I could spot all those cyclic tags, meta-gliders, and pseudo-solitons.
If each frame moved the history ‘window’ by one generation, you’d get a jerky animation. The smooth-scrolling used here shifts the contents by a few pixels in each frame but changes the contents less often. This requires more frames than generations, so 300 frames with a
smoothscrolling value of 10 shows only 30 new generations after the initial bunch.
This GIF does have a few problems; the conflicting demands of file size, image size, image quality, and scroll speed work against each other. There’s a slight flickering, due I think to the rounding or aliasing in the GIF. You could make the GIF as long as you want, subject of course to the maximum size of animated GIF that you’re prepared to handle. (And yes, this page does take a long time to load. Sorry.)
Videos also have their problems with this kind of content, because the downsampling commonly applied can affect the detail. To see what I mean, try watching Rule 110: The Movie (on YouTube). (This is my submission for YouTube’s Most Boring Video 2018 competition.)
If you want to do more than just look at pictures on the screen—perhaps you’re building your own railway station?—here are some tips for exporting the graphics to your favourite 3D modeller.
First, place a box or shape around the outside of the design, and use the
:path action rather than
:stroke. Then, to draw what are now the ‘holes’, use
newsubpath() before drawing each hole, and make sure to draw the holes with reversed paths (using the
reversepath keyword, for example).
So this is a single path, and the holes are reversed subpaths. When you import this single path into a 3D modelling program, you should be able to extrude it into a solid without problems. Here’s one modelled as a thin gold reflective sheet.
It’s hard to resist playing with 3D modellers… I added some fog and a rusty metal effect:
If you omit the surrounding path, it might still work visually. It would be a challenge to hang all these pieces on a gallery wall:
These little critters are quite interesting, and there are a fair number of scientific papers with “cellular automata” in the title . I think this must be because, although things don’t get much simpler than a cellular automaton, perhaps they might—in some strange way—be similar to how the universe itself works when you zoom in close enough.
This page was generated using Literate.jl.
At the time of writing this I couldn’t find any working Julia packages that did one-dimensional cellular automata. But if I had found one, I probably wouldn’t have written any of the above anyway. ↩