Yin Yang Fire

Yin Yang Fire

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.

Yin Yang Fire

Yin Yang Fire

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 (me * 9 + 2 >= cellSum) {
result = result - 1;
if (result < 0) {
result = numStates - 1;
}
}
else {
result = me + 1;
}

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.

Yin Yang Fire

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.

Yin Yang Fire

There is a Long term state vector diagram on this page that shows a variation dropoff around 50000 steps. None of my tests could replicate this, but Thorsten Ewert has been able to confirm that the same drop off does occur using the algorithms shown above.

Yin Yang Fire

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

Yin Yang Fire

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!)

Yin Yang Fire

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.

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. Thanks Thorsten.

Jason.

JavaScript Cellular Automata

Over the last few days I have started learning JavaScript. Creating a simple 2D cellular automata seemed like a good start.

The cells in an outer totalistic CAs get updated based on their 8 immediate neighbouring cells surrounding them. The most famous example would be John Conway‘s Game Of Life.

To see the results of the Outer Totalistic Cellular Automata click here. A bit of CSS to pretty things up and there it is. There is a drop down list of preset rules to show the sorts of emergent behavior that can arise from cellular automata.

If you are interested, the source code is available here.

So far JavaScript has been a relatively pleasant experience. Most of my time was spent on the “how to do” rather than the “what to do”. Once you know the basics of programming any new language mostly comes down to syntax.

Jason.

Multiphase Smoothed-Particle Hydrodynamics

Smoothed-Particle Hydrodynamics (SPH) is a method of simulating fluid flow. It is based on representing a fluid by a large number of discreet (individual) particles. Each particle has properties like position, pressure, density, mass, etc. The particles are fed through a bunch of equations that make them move in a fluid like flow.

If you are a maths nerd then one of the better and recommended papers for SPH fluids is Particle-based Viscoelastic Fluid Simulation.

Multiphase SPH is when you have 2 or more fluids with different densities etc (think oil and water) that flow around each other and clump together.

I have always had a fascination with simulating fluids. Over the years I have tried to understand SPH and have had many failed attempts at writing programs to do it (the basic formulas seem relatively simple, but getting the code to run stable without explosions and crashes is far from simple). Then I found this blog post by Tom Madams that had sample source code. With that I was finally able to get SPH working. It can still be fiddly to find a nice set of parameters to make a nice looking movie, but Tom’s code seems to be a great start. Thanks Tom!!

Multiphase SPH is now available in Visions Of Chaos.

A future release will include 3D support.

Jason.

Cyclic Cellular Automata

Cyclic Cellular Automata were first developed by David Griffeath at the University of Wisconson.

The rules are relatively simple;

1. Take a 2D grid of cells.
2. Select a maximum number of states each cell can have.
3. Select a threshold value.
4. Fill the cells with random state values between 0 and (maximum states-1).
5. At each step of the simulation every cell follows these rules;
a) Count how many neighbouring cells (Moore or Von Neumann neighborhoods) surrond the cell with a value of the current cell’s state + 1
b) If the count is greater or equal to the threshold value then the cell state is incremented by 1
6. Repeat this process as long as you want to.

By following those steps you can get emergent behaviour of spirals and other patterns. Here are a few examples (click the title to watch it in HD format on YouTube);

The different rules (every 10 seconds) in the above video are;
313 (David Griffeath)=1/3/3/M
Amoeba (Jason Rampe)=3/10/2/N
Black vs White (Jason Rampe)=5/23/2/N
Black vs White 2 (Jason Rampe)=2/5/2/N
Boiling (Jason Rampe)=2/2/6/N
Bootstrap (David Griffeath)=2/11/3/M
CCA (David Griffeath)=1/1/14/N
Cubism (Jason Rampe)=2/5/3/N
Cyclic Spirals (David Griffeath)=3/5/8/M
Diamond Spirals (Jason Rampe)=1/1/15/N
Fossil Debris (David Griffeath)=2/9/4/M
Fuzz (Jason Rampe)=4/4/7/N
Lava Lamp (Jason Rampe)=3/15/3/M
Lava Lamp 2 (Jason Rampe)=2/10/3/M
Maps (Mirek Wojtowicz)=2/3/5/N
Perfect Spirals (David Griffeath)=1/3/4/M
Stripes (Mirek Wojtowicz)=3/4/5/N
Turbulent Phase (David Griffeath)=2/5/8/M
The 2/5/8/M refers to Range/Threshold/States/Neighborhood.

The same principle works in 3D too. You just need to expand the neighborhood checks to cover 3D space.

2D and 3D CCA are now included in the latest version of Visions Of Chaos.

Jason.

Fractal Planets

After reading this page from Paul Bourke I had a go at creating fractal planets by one of the methods he mentions;

1. Take a sphere of points (best to use a geodesic sphere so the points are evenly spread over the surface of the sphere).

2. Cut the sphere in half with a plane that goes through the origin. See the section on Great Circles here.

Great Circle

3. All points on one side of the plane are moved outwards and all points on the other are moved in.

4. Repeat this process a few hundred times and you get a fractal planet.

5 steps
fractal planet

50 steps
fractal planet

100 steps
fractal planet

250 steps
fractal planet

500 steps
fractal planet

And here is a movie of the creation process.

Fractal planets are now included in the latest version of Visions Of Chaos.

Jason.

Karl Sims

If you are a nerd then you most likely have heard of Karl Sims. If you haven’t heard of him give his page a browse as there is some good stuff there.

I have admired and respected him since his work in Genetic Images back in 1993 that inspired all three of my attempts at Genetic Art so far. I still have a few more ideas on new Genetic Art methods to experiment with and share when I get some spare time.

I noticed his latest work as I was browsing Reaction Diffusion videos on YouTube. Yes, if you know what to look for there are videos on YouTube better than this one that was featured on their homepage and has millions of hits so far. I must be getting old(er)… “What is wrong with kids these days”!?

Check these two RD samples Karl put up on YouTube.

The most impressive aspect of those is the shading that gives them the 3D look. (Aussies can confirm the almost exact reflectance of the second example to Vegemite). Remember that the output of these Reaction Diffusion equations is strictly 2D. The bulging 3D look is based on calculating the slope between neighbouring pixels. Or at least that is how I do it in Visions Of Chaos, but Karl’s versions seem so much more 3Dish than mine. See his images here that are awesome.

As always he inspires me (and I am sure many others) to do better.

Jason.