My itch.io account, alexmulkerrin.itch.io, has been steadily gaining new entries but I haven't really written about a lot of them here or if I have it was a long time ago. To that end I thought I'd go over each of them a little and go into what it is, why I made it and what I like to add or improve it with.
For the first entry in this series I thought I'd go for that old classic Cellular Automata Sim
The What
Cellular Automata Sim is the very first thing I uploaded to itch.io back in 2020. Whilst it isn't the first time I've dabbled with Cellular Automata or putting it online link it is an iteration that I'm rather proud of for how fully featured I made it.
Cellular Automata are one of the most interesting mathematical concepts as they use extremely simple rules to generate complex phenomena. The classic version of Cellular Automata is Conway's Game of Life that has a grid of square cells which can be in two states, playfully referred to as alive or dead. The rules for what happens to a cell are very simple. If a cell is dead it comes alive if it has 3 neighbours, if alive it remains alive if it has 2 or 3 neighbours, otherwise it dies. That is all it takes to get some fascinating phenomena.
Indeed if you boot up Cellular Automata Sim that is the ruleset that will be displayed first and the grid will be populated with a random spread of alive cells that quickly evolve into complex patterns.
On the interface there are buttons for randomising the grid cells, clear the grid, slowdown, speedup or pause the simulation and zoom in the size of the cells in or out. You can left click on the grid to add an alive cell, right click to remove it.
Now that is not all as below the buttons is a table of the ruleset and a selection of 8 preset rules. It is this part of the simulation that I'm most proud of.
The Why
The ruleset of Conway's Game of Life has lots of neat emergent phenomena, patterns that stay in place, move at a fixed rate across the screen, grow or shrink. But that is just with one ruleset, what if you could change what the cells do on having any permutation of alive or dead neighbours. Would the Cellular Automata take different properties in how it evolves?
The answer is yes and if you experiment with the presets you can see all kinds of neat phenomena. You could make islands of alive cells, a maze like pattern that symmetrically expands from a single cell, a duplicator that copies its pattern to spaces around it before disappearing, very minimal patterns that expands out from two adjacent cells to create a wavefront with static behind it. I could go on and on and this is only scratching the surface with just the rulesets available in the presets.
Here are a few of the patterns you can find, often a ruleset acts differently if you start with an empty grid with only a few cells compared to a purely random start.
There are literally thousands of possible combinations for a ruleset to be in, 65,535 to be particular but many are mirrors of each other. I'd thoroughly recommend sitting down and exploring with it.
It wasn't difficult to make the code to allow you to change the ruleset but I am pleased with how elegant it was when compared to example cellular automata code that uses explicit if-else statements for each permutation of neighbours. Instead with a simple 2 dimensional array all it takes is a lookup depending on the cells state and how many neighbours it has.
The Future
Because this project has been on itch for so long I do often think about going back to it and extending it. First thing I'd probably do is make the interface nicer. Some tooltips and borders to the buttons would look nice. I'm really not a fan of flat design due to it not communicating what is interactive.
The zoom function is clunky as whilst you can use the mouse wheel it always zooms into the top left corner, often cutting off the part of the pattern you are most interested in. It would be sensible if the mouse position was used to target which part of the pattern you want to zoom in on. This is something I've done in previous projects so it wouldn't be too tricky to implement.
It might be nice to have more complex interactions at the sides of the grid, such as letting the pattern loop around from one side to another. Being able to save patterns and their ruleset would be nice too. A faster algorithm to allow you to make truly massive patterns... The list goes on.
One thing I haven't mentioned is what if the ruleset wasn't limited to 2 states, well that is something I've worked on a bit in other projects and can talk about later.
All in all Cellular Automata Sim is one of my favourite classic projects and a good example of the kind of simulation with emergent phenomena that I'm fascinated by.





No comments:
Post a Comment