Main menu

Fractals, Cellular Automata, Chaos Theory, Science, Space, etc

Monthly Archives: January 2015

Back around 1999 Jack Ruijs discovered a cellular automaton he named Yin Yang Fire. See here for his explanation. Unfortunately he decided to keep the formula a secret after being ignored by “several universities/persons that are working on the field of self organizing system / computer-algorithms etc” so he has never shared the methods that create his Yin Yang Fire images.

I remembered Yin Yang Fire again when I stumbled across this forum post by MackTuesday that has some code he discovered to generate the Yin Yang Fire. Ignoring the name calling and insults, here is the snippet of source code he provides.

// The number of states is 64. In memory they take the values 0-63.
int me = cellsBuffer[x][y];
int result = me;
// cellSum is the sum of the states of the 8 neighbors plus the central cell
// numStates = 64
if (me * 9 + 2 >= cellSum) {
result = result - 1;
if (result < 0) {
result = numStates - 1;
}
}
else {
result = me + 1;
}
return result;

For those of you who have played with cellular automata in the past then this method will be fairly familiar. Update each cell using its value and the total of its 8 neighbours. What is new is the update rule

If you run the rule as is you get a lot of color cycling and flashing as the cell states decrease to 0 and then wrap around to numstates again. This is shown in the following GIF aniumation.

To avoid the pulsating/strobing updates you can update the display every n calculated frames. A good formula I found is to use numstates*1.5 steps between display. So for example the default of 64 states should be shown on screen every 64*1.5 or 96 steps. This gives a smoother (but faster) output as shown in the following GIF.

Alternate neighbourhoods can also be used. This next one used a Von Nuemann (N S E W neighbours only)

If you are an enthusiast of cellular automata reading this, do experiment and let me know about any further discoveries here (without keeping it a secret for 15 years!)

Since writing this post I was contacted by Thorsten Ewert who has done more investigations into the Yin Yang Fire CA. See his page here for more information. For example, there is a Long term state vector diagram on this page that shows a variation drop off around 50000 steps. None of my tests could replicate this, but Thorsten has been able to confirm that the same drop off does occur using the algorithms shown above. Thanks Thorsten.

The latest version of Visions Of Chaos now supports Yin Yang Fire cellular automata and I also hacked together a quick online GLSL shader version here that you can run in your browser. It seems to run best under Chrome.