Water Animations and Sailboat Automata in MATLAB

Francisco Sebastiano
3 min readJul 11, 2023

--

Just like everyone else interested in CS and CE, I’m enamored with cellular automata. The simple rules and chaos and emergent behaviors beg any programmer with a soul to start experimenting. About 2 weeks ago, with dreams of having a rule set named after me, I tried to write the next great cellular automata program.

All of the programs I wrote for this article are in a Github repository: https://github.com/franciscoSebastiano

The First Conway’s Game of Life Script I Wrote in MATLAB

3-state Cellular Automata

I started scripting in MATLAB partially because I had just gotten access to it through my university and partially because I thought the way MATLAB handles matrixes (by making everything a matrix) would suit cellular automata really well.

The first Conway’s Game of Life program I wrote worked great, so I tried to change that by making my own modifications to Conway’s rule set. What if it took a cell two cycles to die instead of one? The cells could have three states: living, sick, dead. A cell would need to go two cycles without the correct number of neighbors before said cell dies. Sick cells could be yellow. That program is shown by the below gif.

A Really Bad Version of Conway’s GOL With 3 Cell States

The addition of sick cells caused the simulation to find an immediate and uninteresting static equilibrium. The program starts with each cell value being randomly assigned, which is why there are so many cells at the beginning of the above gif. These cells all die, however, as the previously mentioned equilibrium is found.

Rule Set for Many-State Cellular Automata

Many-State Cellular Automata

Maybe 3-state automata was a flop, but who’s to say that adding more states won’t make things better? I modified Conway’s game of life so that a dying cell loses 0.5 health points and a thriving cell gains 0.5 health points. A snapshot of the code is pictured above. It’s important to note that the “num_neighbors” value in my program is calculated by finding the sum of health values of neighbors around a given cell. This means that high health cells will put a resource strain on on their cell neighborhood, causing cells in such a neighborhood to die off. Similarly, super low health cells will not contribute to their neighborhood and will also cause other cells to die off. Below is a gif of this configuration.

Note: (The compression algorithm used to get these gifs onto medium is brutal, so I apologize for how poor the quality is).

Many State Cellular Automata

This was the first time I got anything mildly cool looking out of one of my own rule sets. Sure, it’s not much, but it kind of looks like shimmering water. I graphed my water animation an 3d using the surf() function, and got the below result:

The gif quality was so bad that I had to insert the video through youtube

I really liked the way the 3d water animation looked, so I decided to add a boat bobbing on the water. The idea was inspired by the sailboat automata toy. If you’ve never seen a sailboat automata, I added a video of one below (curtsey of Sven Furslund on youtube).

To replicate the sailboat automata with cellular automata I imported an 3d model of a boat as an stl file, then used the trimesh() function to plot the boat in the 3d graphing window. This video was really helpful for that process. To move the location of the boat around in the graphing window I applied shifts to the STL file position, then rotated the file with a rotation matrix as is described in this video. Lastly, I wrote some conditional statements to move the boat in accordance with the height of the water around it (tall wave in front of boat and small wave behind boat causes boat to move back and pitch up, etc). Below is a video of the cellular sailboat automata. The music is ridiculous, but so is the project.

Cellular Water + Sailboat

Since this article is on medium and not on the cover of Nature Computational Science, it’s clear that I did not create the next great cellular automata rule set. I did learn a lot while trying, though, and ended up with a neat animation.

--

--