Cellular Automata models in Java
This page contains links to several cellular automata Java applets. They are still very unpolished prototypes, but available to play around with. Feedback is welcome. The source code is not being widely released yet. I plan to clean up the code when I have time, and then release it. If you really want it before then, please contact me.
To see the applets, you need a Java-compatible browser, with a relatively recent version of Java (if things don't work properly, try checking to see if there is a newer version of Java than what you currently have installed). And of course Java support has to be turned on. See below for more information on Java and web browsers.
Here are the applets so far (hopefully more will be added later):
- Conway's Game of Life, a well-known cellular automaton in which sites die if they are too "lonely" or "crowded" but persist otherwise, and dead cells become alive if the population density in the neighborhood is at an intermediate level.
- MajorityLD, in which cells change their state to whatever is the most common state in (a sample of) their neighborhood. This rule includes a user-specified amount of long-distance interactions, and allows for discrete- or continuous-time updates, i.e. synchrononous or asynchronous. (This applet can be used to explore the voter model I explored in my paper "Transient Dynamics and Quasistationary Equilibria of Continuous-time Linear Stochastic Cellular Automata Voter Models with Multiscale Neighborhoods," Advances in Complex Systems, 10 (suppl. no. 1), 145--165 (2007).
- Cyclic, a rule based on the idea of "rock, paper, scissors" (rock, scissors, cloth, i.e. "shi2 tou, jian3 zi, bu4" in Chinese). A cell looks at (a sample of) its neighbors. If the cell is in state i and any of the neighbors examined are in state i+1, then the cell being considered changes it state to i+1, i.e. state i+1 "beats" state i. Also, state 0 "beats" the largest state, thus closing the "rock, paper, scissors" loop.
- DLA (Diffusion Limited Aggregation), in which blue particles diffuse randomly; if a blue particle is ever adjacent to a green particle, it turns green and "sticks", i.e. stops moving.
- Predator-Prey, a spatial population ecology model, which allows you to investigate the effects of different spatial scales of activity for the two species.
- Block Extinctions, a spatial population ecology model, where the population is disturbed in spatially contiguous blocks, rather than individual sites being disturbed independently as in most models. This implements the model described in my paper "Spatially Correlated Disturbances in a Locally Dispersing Population Model", Journal of Theoretical Biology 232 (1), 143--149 (2005).
You can think of a cellular automaton model as a piece of graph paper, with many small squares, called cells. Each cell can have one of several colors. Or instead of colors, you could use numbers to describe the value in each cell (the values are called "states").
The squares are updated as follows. A clock ticks regularly, and on every tick of the clock (every "time step"), each cell examines its own value, and the values of some of its neighbors. It uses those values, and follows a kind of recipe or rule, which describes what its new state will be after the clock-tick. Every cell does this simultaneously, using its own value and the values of some of its neighbors, to compute their new value. They then all change their state to their new values, all at once.
It sounds somewhat abstract. But cellular automata models have been used for many things, from simple attractive "screen savers", to studying the theory of computation, to modeling phenomena in physics, ecology/biology, geology, and fluid flow.
Note, you should left-click on buttons such as "Start" or "Stop", and right-click to pop up menus such as "Array Operations", etc.
- From the "Array operations" menu, you can either choose "Clear" to set all cells to state 0, or "Random" to set each cell to a random state (all states having equal probability).
- Press the "Single Step" button to run a single time step.
- Press the "Start" button to run continuously. (The button then turns into a "Stop" button, which you can press to stop running.)
- You can select the running speed, from among Slow, Fast, and Fastest.
- The "Time step" label indicates how many time steps have been run (the counter is reset by certain operations).
- You can use the mouse to "draw" in the array in order to change the states of cells. The "Drawing state" item lets you specify which value the mouse will draw into the cells.
- The Drawing Brush Size lets you draw more than one cell at a time; you can draw an NxN box of cells (the mouse is at the upper-left corner of the "paint brush").
In addition, some rules have their own special controls, e.g. which let you change the number of states, or vary the neighborhood used, etc. See the individual applets' web pages for more information.
Pretty much all major web browsers currently have support for Java, although you may have to jump through some hoops to get it installed, depending on your platform.
If you don't have Java installed, you can download it from java.sun.com. The simplest thing to download in order to run these applets is the Java Runtime Environment (JRE) for the Java 2 Platform, Standard Edition (J2SE). At the time of this writing, the current version is J2SE 1.4.2 which you can download from here. You don't need the Software Development Kit (SDK) unless you will be programming Java yourself.
I've recently started using some machines running OS-X, and have found that when these applets are run within Firefox, the image updates very infrequently (i.e. not every frame is displayed), even though the simulation itself runs along steadily. Running the applets in Safari gives much smoother updates, i.e. the image is refreshed regularly. I have no idea why this happens; if you do, and better yet know how to fix the problem, please let me know.
Some books discussing cellular automata are:
- The Computational Beauty of Nature, by Flake, MIT Press, 1998.
- Cellular Automata: Theory and Experiment, edited by Gutowitz, MIT Press, 1991.
- Cellular Automata Machines: A New Environment for Modeling, by Toffoli and Margolus, MIT Press, 1987.
I developed this software with support from a Learning Circles Grant (with co-PI's Larry Latour, Raymond O'Connor, Jim Wilson, and Liying Yan) from the UMaine Center for Teaching Excellence, and a Faculty Technology stipend from the UMaine Department of Information Technologies.
I was inspired to write these in part by a couple of workshops/courses on complex adaptive systems I co-taught with the above colleagues and with Huijie Xue, and by the students in my various classes who wanted to play with my simulations which until that point would only run under Linux since I'd written them in C using X11 for the graphics.
My first versions of these applets were based on a Game of Life Java applet by Edwin Martin.