When I was in High School
- People were walking on the moon,
- I was learning to program with BASIC and,
- I learned about Cellular Automata from Scientific American, and I thought it was really neat.
Now, no one is on the moon, I mostly don't program in BASIC... but I still think Cellular Automata is pretty neat. So much so, it's one of my go-to things to fool around with on different tiny devices - micro:bit, Circuit Playground, and, of course, my favorite NeoTrinkey!
I've got a repository with some of my experiments.
The first is lca.py .  This lets you run a linear cellular automata on the Neo. Run it as "code.py" or, in Thonny, load it up and click the "run" icon. It's a simple program that will run 10 generations every time you touch pad #1. Touching pad #2 randomizes the universe. Output is printed to the REPL - but the four pixels of the Neo will show four of the cells with random colors.
Output looks like this:
Recently I learned of the mathematician Nils Barricelli, who did early work in the 1950's to simulate life
George Dyson described Barricelli's first experiments at Princeton:[8]
At 10:38 p.m. on March 3, 1953, in a one-story brick building at the end of Olden Lane in Princeton, New Jersey, Italian-Norwegian mathematical biologist Nils Aall Barricelli inoculated a 5-kilobyte digital universe with random numbers generated by drawing playing cards from a shuffled deck. "A series of numerical experiments are being made with the aim of verifying the possibility of an evolution similar to that of living organisms taking place in an artificially created universe," he announced.
This inspired me to create simbio.py. Running this as code.py (or in Thonny, opening it and "running it") will go through successive generations. Touch pad #1 to toggle on/off the running of generations. Touch pad #2 to randomize the universe - the four pixels show a glimpse of the generations, but the REPL will show:
Â
If ALL cells "die" the four pixels will flash white and the universe will be rebooted with a random restart. More often the universe will settle down to a cyclic pattern that repeats continuously.
Finally, inspired by "Is Micropython better than BASIC?" I thought about writing my own Life simulator in CircuitPython and came up with life.py - (which requires prt.py and ncount.py; the prt.py lets you redirect output to HID keystrokes if REPL=False, and ncount.py is for some blinking lights).
Run as code.py, or in Thonny from the "run" button, it will generate multiple runs of different patterns:
- blinkers - cyclic patterns of three dots
- bars - a vertical bar; the universe is a torus, so the bar is a "ring"
- glider - a moving pattern that slowly inches across the universe
- rpentonimo - a pattern that generates more complexity
- random start - salts the universe with random cells
Â
At the bottom of the code you'll see:
for p in [blinkers,bar,glider,rpent]: # each defined pattern  dopat(p) # salt universe with pattern  showU() # display pattern  rungens(10) # run 10 generationsrandU() # salt universe with random cellsshowU() # show universerungens(10) # run ten generations.
Â
For fun:Â
- comment out that section
- then, in the REPL type "from life import *"
Then you can type, for example
randU()
showU()
rungens(10)
Â
or
dopat(glider)
showU()
rungens(10)
For more fun, you'll find "live.py" in the repository. This is a Python version of life.py that you can run on it's own in a Python interpreter.
Â
Â
As always, the NeoTrinkey is small, but mighty - containing a whole universe of possibilities to bring to "LIFE!"
This page (It's ALIVE! Cellular Automata on the NeoTrinkey!) was last updated on July 02, 2024.
Text editor powered by tinymce.