Conway's Game of Life

Pan      
     
      

Click to create, Shift-Click to erase, Ctrl-Mouse to select

This implementation uses JavaScript and SVG, both of which are supported by all major modern browsers. If this page does not work with your browser, consider upgrading.


The Nature of Life

Conway's Game of Life simulates the birth and death of cells on a rectangular grid. The state of a given cell in any generation depends on the state of the cell and its eight immediate neighbors in the preceding generation, according to some simple rules:

As simple as these rules may be, they can result in surprising complexity from relatively simple initial configurations.

The Shape of the World

In principle, the Life universe is an infinite grid. In practice, implementations generally impose some constraints. This implementation allows you to configure those constraints at any time, even as the universe is evolving.

Topology

You can choose among three topologies:

Width and Height

You can set the width and height to any reasonable integer values. If you specify a non-numeric value, or a value which is too large or too small, the default value will be used instead.

Color

You can choose among four color schemes:

Creating and Deleting

To create live cells, click on the grid with the left mouse button. You can also click and drag, which produces a line of live cells along the path of the mouse cursor.

To delete cells, do the same as for creating cells, but hold the Shift key down while doing so.

You can press and release the Shift key without having to release the mouse button. Whenever the Shift key is down, you are deleting cells. Whenever it is up, you are creating cells.

Starting and Stopping

Once you have an initial configuration of cells, click on the Evolve button. The universe will then evolve for the number of generations specified in the input field to the left of the Evolve button. You can stop evolving by clicking on the Stop button.

The number of milliseconds between generations is determined by the Delay value, which you can set between 0 and 60000 (one minute).

Panning and Zooming

Use the various arrow buttons (above the grid) to pan:

The Zoom In button zooms in by a factor of 2, while the Zoom Out button zooms out by a factor of 2. There are limits on how far you can zoom.

Cutting, Copying and Pasting

If you discover an interesting pattern which you'd like to move or replicate, you can do so by cutting or copying it and pasting it.

To select a region of cells (or a location for pasting), hold the Ctrl key while clicking and dragging with the left mouse button. The selected region will be shown as a light red color.

Once you have selected a region, you can use the Cut, Copy and Paste buttons. A cut or copied pattern is shown in the square at the top right of the grid. This is what will be pasted when you press the Paste button.

To rotate the pattern clockwise 90 degrees, click the Rotate button.

To flip the pattern vertically, click the Flip button.

Loading Patterns

There are a number of well-known cell patterns in Life, such as the glider and the block. Many of these are available for loading into the pattern buffer, from which you can then paste them into the world.

To load a pre-defined Life pattern, click on the index selector, to the right of the Save button. The index selector presents a combination of life patterns and other indexes.

To load a Life pattern from a local file, click on the file selector, to the right of the index selector.

Pattern Files

Life pattern files conform to a simple format. Each line of the file represents a row, with each character on the line representing a column in that row. Blank cells are represented by space or dot characters, while other characters represent living cells.

Comments are an exception to the above. Any line whose first column is the comment character ("#") is ignored, and does not count as a row. Also, within a line, everything at and after the comment character is ignored. Thus, the following defines a 3-by-3 pattern (trailing blanks are ignored) for a glider:

# description: Glider
.O.    # This particular glider
..O    # is headed toward the
OOO    # lower right.
# End of glider

If a Life pattern file contains a "description:" comment (on a pure comment line, not as a trailing comment), that comment will appear to the right of the index selector and the browse fields when the file is loaded.

Note that the format of a Life pattern file actually allows you to load an arbitrary file and treat it as a Life pattern. While this is usually a silly thing to do, it is legal.

Index Files

A Life file can act as an index to Life pattern files and other Life index files. A Life index file consists solely of comments. Each comment of the form

# file: file_name
or
# file: Brief description = file_name
specifies a Life pattern file or index file which can be loaded. The description is the text which appears in the selection field when the index is loaded.

If a Life index file contains an "index:" comment, that comment will be used as the label for the index selector.

By convention, the brief description for an index file has a trailing "...", to differentiate it from a pattern file.

Saving Patterns

To save a Life pattern for future loading, copy it to the pattern buffer and press the Save button. The pattern will be saved with a name and optional description which you specify. You can later load the pattern via the Saved Patterns index, which is accessible from the Main Index.

Patterns are saved to local storage in your browser. You may want to remove old Life storage from time to time, using the appropriate interface within your browser.

Clipboard

Life patterns cannot be saved directly to a local file. However, you can copy the current pattern to the clipboard and then paste from the clipboard into an application of your choice.

To copy the current pattern to the clipboard, click on it in the square at the top right of the grid.


To contact me, send mail to dewara@cuug.ab.ca.

Alan Dewar's home page            CUUG home page