back

31.07.2014 by noniwoo

EnergySimulation

Cellular automata are interesting piece of computer science - small programs with simple rules, which during work can produce interesting shapes and behaviours.

Because some cellular automaton came to my mind, I've decided to write it. After few days of learning SDL2 and programming, I've created a small program which gives very interesting effect. But first talk a bit about rules.

Every cell has its value (energy) as a (non-negative) integer. In every iteration it distributes its energy to neighbours, equally over them. If some piece of energy cannot be divided equally between neighbours, that rest stays inside the cell.

For example:

cell value = 20
number of neighbours = 8
distributed value per every neighbour = 20 / 8 = 2
cell value after iteration = 20 - (2*8) = 4

Cell space is a regular grid with finite size, thus cells at edges have less neighbours. It is not an infinite space nor continuous at edges (in a sense that going through one edge you are next to the opposite one).

Start of simulation is a single cell at the centre of the grid with a big value eg. 1000000. Final effect, simulation program and its source code are available below.

If you would like to know more about similar things, look for: cellular automata, emergence and (a bit distant but giving similar effects) cymatics.

Example image of a final step of the simulation

EnergySimulation

Program source + project in MS Visual C++ 2010 + Makefile for Linux (thanks to dozzie): EnergySimulation source

Program for Windows: EnergySimulation Windows bin