Home

Awesome

LifeViewer

This is LifeViewer, a scriptable pattern editor and viewer for Life-like cellular automata. Designed to be easy to embed in your own web site.

Currently used on:

Written in plain Javascript/HTML5 without any external libraries.

Contents

What does it do?

LifeViewer simulates and animates cellular automata in the web browser.

LifeViewer features:

LifeViewer supports several different pattern formats, rules and neighbourhoods, as well as bounded grids.

TopicSupported
Pattern formatsRLE, Life 1.06, Life 1.05, Cells
RulesWolfram, Totalistic, Generations, Isotropic Non-Totalistic, MAP, Larger than Life, HROT, Alternate, Margolus, PCA, RuleTable (@TABLE, @TREE and @COLORS), Weighted
Bounded GridPlane, Torus, Klein, Cross-Surface, Sphere
States2 to 256 states, [R]History, Niemiec, Generations
NeighbourhoodsMoore, Hexagonal, Von Neumann, Triangular, 1D, Circular, Cross, L2, Saltire, Star, Checkerboard, Hash, Tripod, Asterisk, Custom

How do I use it?

<!DOCTYPE html>
<html>
    <head>
        <meta name="LifeViewer" content="viewer textarea 30 hide limit">
        <script src="js/lv-plugin.js"></script>
    </head>
    <body>
        <h1>This is LifeViewer</h1>
        <div class="viewer">
            <textarea>3o$bbo$bo!</textarea>
            <br>
            <canvas width="560" height="560"><canvas>
        </div>
    </body>
</html>

You can put multiple LifeViewers on a single page. Each time you want one just specify an enclosing <div> containing both the <textarea> with the pattern definition and a <canvas>.

<div class="viewer">
    <textarea>bo$2bo$3!</textarea>
    <canvas width="560" height="560"></canvas>
</div>

If you omit the <meta> tag then it defaults to the following settings (which are used on the ConwayLife Forums):

<meta name="LifeViewer" content="rle code 37 hide limit">

In addition to having one or more LifeViewers embedded in a web page a single popup LifeViewer is also allowed which can be launched in a moveable window above the current page.

In this case create an anchor <a> element within the LifeViewer <div> as follows:

<div class="viewer">
    <a href="" onclick="updateViewer(this); return false;">Show in Viewer</a><br>
    <textarea>bo$2bo$3!</textarea>
</div>

Note there is no need for the <canvas> element in this case since the pattern will be drawn on the popup window.

Once you have built the plugin you can see both embedded and popup LifeViewers in action in this example.

How do I build it?

The build folder contains scripts to create the single minified plugin file lv-plugin.js from the source files in the js folder.

On Windows: From the build folder run compile.bat. This requires Java and the included Google Closure compiler compiler.jar. The path to Java is hard coded in compile.bat and will need to be updated to wherever Java is installed on your machine.

On MacOS or Linux: From the build folder run ./compile.sh. This requires Java and the included Google Closure compiler compiler.jar.

Folders:

FolderDescription
buildbuild script and Google Closure compiler
imagesicons for UI and keyboard map
jsJavascript source files
testsHTML test cases

Source files:

FileDescription
aliascommon alias names for rules
allocatortyped array allocation and tracking
boxbounding box
canvasmenuUI library
coloursdefault colour sets for common rules and colour names
compatibilitysome cross-browser compatibility functions
helphelp information
hrotLtL/HROT algorithm
keyskeyboard processing
keywordsscript command keywords
lifealgorithms to compute the next generation
lifeviewmain program
parserscript command parser
patternspattern reader and decoder
randompseudo-random number generator
scriptconverts input into token stream
snapshotsnapshot manager for going back to earlier generations
starsstarfield
waypointwaypoint, POI and label management
windowpopup window management

Running the test cases:

The tests are simple HTML files which run against the uncompiled source files in the js folder. Just open them in your browser.