443d10deaada051f2fdeb69f9b662028b8415883
[screensavers] / hacks / WolframAutomata / README.md

Overview

This WolframAutomata hack displays the time evolution of elementary cellular automata.

These automata consist of a line of cells, each of which may be either on or off. To ensure every cell has neighbors, the two endpoints of the line connect together, thereby forming a circular universe for the cells to inhabit. This line is drawn horizontally on the screen.

Over time, this line of cells evolves according to rules, with some cells switching on or off. Each new application of the rule to the universe is drawn on the screen as a new line directly below the previous generation’s line, leading the screen to scroll vertically.

Since these are “elementary” cellular automata, the rules which govern the time evolution of this system depend only on the current state of a given cell and the state of its two immediate neighbors. These rules are formalized as Wolfram codes, where the code number is directly convertible into a rule set.

For example, the following screenshot demonstrates Rule 110, itself Turing complete as discussed at length in a fascinating paper.

Rule 110 Animated Screenshot

Commandline flags are provided which enable the user to tweak attributes such as length and speed of simulation, cell size, rule number, colors, starting seed, and other attributes. For example, the screenshot below depicts Rule 73 with different colors than the Rule 110 screenshot. Like the Rule 110 screenshot, it uses -cell-size 2 and seeds the simulation with only a single active cell.

Rule 73 Animated Screenshot

In situations where true randomness would lead to visually unappealing displays, this program provides random selection from curated lists. As one example, to avoid randomly selecting visually indistinguishable colors like dark red and brown to depict on/off cells, the program includes a pre-selected list of color pairs that complement each other and chooses randomly from this list.

Status

Complete. Tested on FreeBSD.

Nearly works on Linux. The only problem resides in WolframAutomata_free(), where the call to XFreeGC() results in a linker error. Commenting that line allows WolframAutomata to build and execute on Linux, but creates a memory leak in the X server, resulting in its eventual termination.

Instructions

The included Makefile includes targets for make all to build the hack, make clean to delete any build detritus, and make run to execute the hack.

If you are running on FreeBSD, simply run one of those three commands. Anywhere else, edit the Makefile to suit your environment per the comments included in that file. Note that the Makefile assumes a copy of the screenhack library source code is located at ../screenhack/ relative to this directory.

For assistance setting $(DEFINES) in the Makefile on non-FreeBSD platforms, consider downloading the XScreensaver source tarball, running ./configure in the unpacked directory, and examining the resulting config.h file.

Although WolframAutomata can integrate with XScreensaver, the presence of XScreensaver is not strictly required. WolframAutomata will both build and execute using only the included screenhack library.

Command-Line Flags

Whenever related options exist, such as the following two rule-selection options, the related options are listed in order of precedence.

Where flags instruct the program to make random selections, these selections are re-randomized every time the simulation is reset, such as after a simulation completes or after resizing the window.

CLI: Rule Selection

If neither of the following two options are passed, rules are randomly selected from curated_ruleset_list[] in WolframAutomata.c.

CLI: Simulation Seed

The following seed related CLI flags apply only when using the -true-random-rule or -rule N flags. Without these flags, the program draws rules from curated_ruleset_list[] which also includes curated seeds, all of which override any seed related CLI flags.

If the curated rule list is not in use and none of the following options are specified, the starting seed will contain randomly interspersed active/inactive cells at a 30/70, 50/50, or 70/30 ratio, itself also randomly selected.

CLI: Simulation Length

If neither of the following two options are passed, the simulation runs as though -length 5000 was passed.

Note that an upper limit of 10,000 generations is enforced in order to avoid BadAlloc errors from some X servers. For more details, read WolframAutomata.c starting around the comment, “The maximum number of generations is cell_size dependent. This is a soft limit and may be increased if …”

CLI: Simulation Speed

If neither of the following two options are passed, the simulation runs as though -delay 25000 was passed.

CLI: Cell Dimensions

Individual cells may be displayed as any square number of pixels (e.g. 1x1, 2x2, etc). Increasing the cell size may help with flickering on high DPI monitors displaying chaotic rulesets.

If neither of the following two options are passed, the simulation behaves as though -cell-size 2 was passed.

CLI: Color

At the moment, the program does not allow the user to specify raw RGB values from the command line. Instead, color pairs are selected from color_list[] in WolframAutomata.c by specifying an index (starting from 0) into this array. However, any RGB color the user desires may be added by creating new entries in that array (or editing existing entries) and recompiling.

If the following CLI option is not passed, a random color selection is made from color_list[] at the start of each new simulation run.

Note that the names provided as comments in color_list[] are X11 color names.

CLI: Admiration

When the simulation reaches its end as determined by flags like -length N it will pause for a period of time, allowing the viewer to examine it without interference from scrolling. By default, this ‘admiration window’ is five seconds long.

XScreensaver Integration

In addition to running as a standalone program, WolframAutomata can be integrated into the XScreensaver framework.

To accomplish this integration, begin by installing and configuring XScreensaver via whatever method is appropriate for your operating system. The following instructions assume the filesystem paths used by FreeBSD packages and ports; your paths may differ. After XScreensaver installation, ensure all pertinent config files are created by running xscreensaver-demo and configuring XScreensaver for your system.

After XScreensaver is configured and working on your system, ensure that WolframAutomata runs in standalone mode on your system. If you can make clean run in the screensavers/hacks/WolframAutomata/ folder and see the hack’s visual output, you’re ready to move on.

At this point, copy the hack into your XScreensaver hack directory. For example, with prerequisite steps spelled out:

git clone git://git.subgeniuskitty.com/screensavers
cd screensavers/hacks/WolframAutomata
make clean all
cp WolframAutomata /usr/local/bin/xscreensaver-hacks/wolframautomata

Now create the file wolframautomata.xml wherever your system stores XScreensaver config files and populate it with the contents shown below. For example, on FreeBSD:

vi /usr/local/share/xscreensaver/config/wolframautomata.xml

<?xml version="1.0" encoding="ISO-8859-1"?>

<screensaver name="wolframautomata" _label="WolframAutomata">

  <command arg="-root"/>

  <string  id="rule_number"   _label="Rule number: "      arg="-rule %" />
  <boolean id="rnd_rule"      _label="Random rule"        arg-set="-random-rule" />

  <string  id="seed_density"  _label="Seed density (%):"  arg="-seed-density %" />
  <boolean id="seed_left"     _label="Seed left"          arg-set="-seed-left" />
  <boolean id="seed_center"   _label="Seed center"        arg-set="-seed-center" />
  <boolean id="seed_right"    _label="Seed right"         arg-set="-seed-right" />

  <string  id="length"        _label="Length (gen):"      arg="-length %" />
  <boolean id="rnd_length"    _label="Random length"      arg-set="-random-length" />

  <string  id="delay"         _label="Delay (usec):"      arg="-delay %" />
  <boolean id="rnd_delay"     _label="Random delay"       arg-set="-random-delay" />

  <string  id="cell_size"     _label="Cell size (px):"    arg="-cell-size %" />
  <boolean id="rnd_cellsize"  _label="Random cell size"   arg-set="-random-cell-size" />

  <string  id="color_index"   _label="Color index (int):" arg="-color-index %" />

  <string  id="admiration"    _label="Admiration (sec):"  arg="-admiration-delay %" />

  <_description>
Displays the time evolution of elementary cellular automata.

These automata consist of a line of cells, each of which may be either on or
off. To ensure every cell has neighbors, the two endpoints of the line connect
together, thereby forming a circular universe for the cells to inhabit. This
line is drawn horizontally on the screen.

Over time, this line of cells evolves according to rules, with some cells
switching on or off. Each new iteration is drawn below its predecessor,
leading the screen to scroll vertically over time.

The rules which govern the time evolution of this system depend only on the
current state of a given cell and the state of its two immediate neighbors.
These rules are formalized as Wolfram codes, where the code number is directly
convertible into a rule set.
  </_description>
</screensaver>

The next step integrates WolframAutomata into an individual user’s XScreensaver config via the file ~/.xscreensaver. If preferred, it could instead be done in the global XScreensaver config.

In the ~/.xscreensaver file, create a WolframAutomata entry under the programs: label in the same list as all the other hacks. Position in the list is irrelevant, but ensure you don’t paste WolframAutomata’s entry into the middle of pre-existing, multi-line entries. For context, the example below includes a multi-line entry, a GL entry and a plain entry. All that is needed is to insert the WolframAutomata line somewhere in the programs: list, as demonstrated.

vi ~/.xscreensaver

<snip>
programs:                                                                     \
                                xplanet -vroot -wait 1 -timewarp 400          \
                                  -label -origin moon                       \n\
  GL:                           fireflies -root                             \n\
                                wolframautomata -root                       \n\
                                blitspin -root                              \n\
<snip>

That’s all. Now you can run xscreensaver-demo and select WolframAutomata just like any other hack.

Screen Tearing

Certain combinations of rules and display settings lead to full screen vertical scrolling of alternating light and dark pixels, or other difficult to display patterns. If your display doesn’t include some type of vertical refresh synchronization, such output will look terrible.

If stuck in this situation, changing the output of WolframAutomata to scroll horizontally may help, or simply increasing the cell size.