Really Simple Cellular Automata Software
On the day that I was giving a lecture about cellular automata and excitable media, our department network went down. This left me in the situation of having to write some quick software for my notebook computer to display cellular automata and excitable media. Both programs are actually quite useful, though they obviously lack bells and whistles.
Feel free to modify the source code --- these programs are so simple that it's not hard to do if you are familiar with the C language. This really simple program,
called CA, implements a linear boolean cellular automata in which each element
gets inputs from itself and its two neighbors. Periodic boundary conditions
are used, meaning that the elements on the end of the array get their inputs
from the element on the opposite end of the array. The program uses an ordinary
terminal interface, and starts with random initial conditions. The syntax for
running the program is
CA ruleNumber NSteps Seed Width
ruleNumber
is a number that describes the boolean function of 3 inputs to be applied
to the CA. This notation is explained in the textbook. It should be a number
between 0 and 256. If you write this number in binary form, then the least
significant bit gives the output from input 000, the next bit gives the output
from input 001, and so on. To help the user, the bit pattern corresponding
to the specified rule number is printed out on the first line of the output.
NSteps
is the number of time steps to run the automata.
Seed
sets
the pseudorandom initial condition of the array. If you use the same seed
in two runs, the initial conditions will be the same.
Width
gives
the number of elements in the CA. You will want to set this to be no larger
than the character width of the terminal you are using, typically 80 characters.
If you set it larger than the terminal width, the display will be quite ugly
and hard to interpret.
CA 90 20 343 40
gives 01011010 @ @@@@@@@@@@ @ @@ @@ @@@@ @@ @ @ @@@@ @@ @ @@ @@@@@ @@ @@@ @ @@ @@@ @@@@ @ @@@@@@ @@ @@ @@ @ @@@@ @@ @@@@ @ @ @@ @ @@ @@ @@ @ @ @@ @@@ @ @@@ @@ @@@ @ @@ @@ @ @@@@@@@ @ @@@ @ @@@@@ @@@ @@@@ @@ @@ @ @@@ @ @ @ @ @ @ @ @@@ @@@@ @ @@@ @ @ @ @ @ @@ @ @@ @@ @@ @ @ @ @@ @ @@@@@ @@@ @@@@@ @@ @@@@@ @ @ @@ @@@@ @@ @@@@@@ @@ @@ @ @ @@@@ @@ @@ @@@ @@ @ @@@ @@@@ @ @ @ @ @ @@@@@@ @ @ @@@ @ @ @ @ @ @@ @@ @ @ @ @@@ @@ @@ @ @@@ @@@@ @ @ @ @ @ @@@ @@@ @ @@ @ @ @ @@ @ @ @@ @ @@ @@ @@@ @@@@ @@ @@@@ @ @@ @@@ @ @@ @@ @ @ @ @@ @@@ @ @@@ @@@@@ @@@ @@@@ @@ @@@@@@@ @ @@@ @ @ @ @ @ @ @ @@@ @@ @ @@@ @ @ @ @@ @ @@ @@@@ @ @@@ @ @ @while
CA 14 20 343
40
give:
00001110 @ @@@@@@@@@@ @ @@ @@ @@@@ @@ @ @ @@ @@ @ @ @@ @@ @ @ @@ @@ @ @@ @@ @@ @@ @ @ @@ @@ @ @ @@ @@ @ @ @@ @@ @ @@ @@ @@ @@ @ @@ @@ @@ @ @@ @@ @@ @@ @@ @@ @@ @ @@ @@ @@ @ @@ @@ @@ @@ @@ @@ @@ @ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @ @@ @@ @@ @@ @@ @@ @@ @ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@
Compiling this Program:
The display of this program is oriented around the UNIX curses utilities. These
utilities are also available on DOS and WINDOWS machines. When you compile this
progam you will have to link to the curses library, using a command like:
cc life.c -o life -lcurses -ltermcap
Note: some Linux systems have a bug in their curses library that makes the display
flash off. I have not had this problem on other systems or even on older Linux
systems. The syntax is:
life ruletype starttype seed sleep
where
ruletype
is either L or H, depending on whether you want to use Life, or the cardiac
conduction model. The rules of Life are these: Elements are either on or off. If an element is on, and 2 or 3 of its eight neighboring elements are on, then the element stays on. Otherwise it turns off. If the element is off, and 3 of its eight neighbors are on, the element turns on.
The cardiac conduction rules are described in the textbook. Here, the refractory time is 5 time steps.
starttype
tells how to start the model. If this is 0, then a random initial condition
is used. This is often quite interesting. If this is 1, then a highly ordered
initial condition is used. For Life, this is just a cluster of 4 on elements.
For the cardiac model, this is a line of excited elements on top of a line
of refractory elements. This configuration produces a spiral wave. If the
startcode is 2, then the cardiac conduction model will be started with a single
point stimulus.
For the Life rule,
you can specify a startype which is a pattern of the initial condition.
For instance, using
11111-10001-10001-10001-11111
will put a 5 by 5 hollow square in the center of the field.
Seed
sets
the pseudorandom initial condition of the array. If you use the same seed
in two runs, the initial conditions will be the same.
sleep
tells
how long to wait in seconds between iterations. This must be an integer. Set
it to 0 to run the display quickly. Setting it to 1 or 2 usually gives enough
time to figure out what is happening for simple configurations. Note that
you can always use
life L 101-011-010 343
0
@ @ @@ @
life H 1 343 0
@
mean excited, while +
and .
mean refractory. A blank
space means the element is quiescent and therefore excitable. @+@ ..+++@ @+++@ ..+++@ @+++++@ ..+++@ @+++.+++@ ..+++@ @+++...+++@ ..+++@ @+++.. ..+++@ ..+++@ @+++.. ..+++@ ..+++@ @+++.. @ ..+++@ ..+++@ @+++.. @+@ ..+++@ ..+++@ @+++.. @++ ..+++@ ..+++@ @+++.. @+++...+++@ ..+++@ @+++.. @+++.+++@ ..+++@ @+++.. @+++++@ ..+++@ @+++.. @+++@ ..+++@ @+++.. @+@ ..+++@ @+++.. @ ..+++@ @+++.. ..+++@ @+++.. ..+++@ @+++...+++@