Small changes after proof-reading of WolframAutomata README.
[screensavers] / hacks / WolframAutomata / README.md
CommitLineData
74edf561
AT
1Overview
2========
3
4This WolframAutomata hack displays the time evolution of [elementary cellular
5automata](https://en.wikipedia.org/wiki/Elementary_cellular_automaton).
6
7These automata consist of a line of cells, each of which may be either on or
8off. To ensure every cell has neighbors, the two endpoints of the line connect
9together, thereby forming a circular universe for the cells to inhabit. This
10line is drawn horizontally on the screen.
11
12Over time, this line of cells evolves according to rules, with some cells
f6e3cf3e
AT
13switching on or off. Each new application of the rule to the universe is drawn
14on the screen as a new line directly below the previous generation's line,
15leading the screen to scroll vertically.
74edf561
AT
16
17The rules which govern the time evolution of this system depend only on the
18current state of a given cell and the state of its two immediate neighbors.
19These rules are formalized as
20[Wolfram codes](https://en.wikipedia.org/wiki/Wolfram_code),
21where the code number is directly convertible into a rule set.
22
23For example, the following screenshot demonstrates
24[Rule 110](https://en.wikipedia.org/wiki/Rule_110), itself Turing complete as
25discussed at length in a
26[fascinating paper](https://arxiv.org/pdf/0906.3248.pdf).
27
28![Rule 110 Animated Screenshot](/screensavers/.git/blob_plain/HEAD:/hacks/WolframAutomata/screenshot_rule_110.gif)
29
f6e3cf3e
AT
30Commandline flags are provided which enable the user to tweak attributes such
31as length and speed of simulation, cell size, rule number, colors, starting
32seed, and other attributes. For example, the screenshot below depicts Rule 73
33with different colors than the Rule 110 screenshot. Like the Rule 110
34screenshot, it uses `-cell-size 2` and seeds the simulation with only a single
35active cell.
74edf561
AT
36
37![Rule 73 Animated Screenshot](/screensavers/.git/blob_plain/HEAD:/hacks/WolframAutomata/screenshot_rule_73.gif)
38
39In situations where true randomness would lead to visually unappealing
004edcbf 40displays, this program provides random selection from curated lists. As one
74edf561
AT
41example, to avoid randomly selecting visually indistinguishable colors like
42`dark red` and `brown` to depict on/off cells, the program includes a
43pre-selected list of color pairs that complement each other and chooses
004edcbf 44randomly from this list.
74edf561
AT
45
46
47Status
48======
49
50Complete. Tested on FreeBSD.
51
52Nearly works on Linux. The only problem resides in `WolframAutomata_free()`,
53where the call to `XFreeGC()` results in a linker error. Commenting that line
54allows WolframAutomata to build and execute on Linux, but creates a memory leak
55in the X server, resulting in its eventual termination.
56
57
58Instructions
59============
60
61The included `Makefile` includes targets for `make all` to build the hack,
62`make clean` to delete any build detritus, and `make run` to execute the hack.
63
64If you are running on FreeBSD, simply run one of those three commands. Anywhere
65else, edit the `Makefile` to suit your environment per the comments included in
66that file. Note that the `Makefile` assumes a copy of the screenhack library
67source code is located at `../screenhack/` relative to this directory.
68
f6e3cf3e
AT
69For assistance setting `$(DEFINES)` in the `Makefile` on non-FreeBSD platforms,
70consider downloading the XScreensaver source tarball, running `./configure` in
71the unpacked directory, and examining the resulting `config.h` file.
74edf561
AT
72
73Although WolframAutomata can integrate with XScreensaver, the presence of
74XScreensaver is not strictly required. WolframAutomata will both build and
75execute using only the included screenhack library.
b020506b
AT
76
77
78Command-Line Flags
79==================
80
81Whenever related options exist, such as the following two rule-selection
82options, the related options are listed in order of precedence.
83
84Where flags instruct the program to make random selections, these selections
85are re-randomized every time the simulation is reset, such as after a
86simulation completes or after resizing the window.
87
88
b020506b
AT
89CLI: Rule Selection
90-------------------
91
92If neither of the following two options are passed, rules are randomly selected
93from `curated_ruleset_list[]` in `WolframAutomata.c`.
94
95 - **`-true-random-rule`**: Select a rule completely at random, NOT randomly
96 from a curated list. Note that many rules are visually uninteresting.
97
98 - **`-rule N`**: Select a specific rule where `N` is a Wolfram number. Values
89ff0c45 99 from 0-255 inclusive are valid.
b020506b
AT
100
101
6b4b1b56
AT
102CLI: Simulation Seed
103--------------------
b020506b 104
6b4b1b56
AT
105The following seed related CLI flags apply only when using the
106`-true-random-rule` or `-rule N` flags. Without these flags, the program draws
107rules from `curated_ruleset_list[]` which also includes curated seeds, all of
108which override any seed related CLI flags.
b020506b 109
6b4b1b56
AT
110If the curated rule list is not in use and none of the following options are
111specified, the starting seed will contain randomly interspersed active/inactive
112cells at a 30/70, 50/50, or 70/30 ratio, itself also randomly selected.
b020506b 113
6b4b1b56
AT
114 - **`-seed-left`**: Seeds a single active cell on the left side of the
115 display. All other cells are inactive.
116
117 - **`-seed-center`**: As above, but in the center.
118
119 - **`-seed-right`**: As above, but on the right side.
120
121 - **`-seed-density N`**: Generates random seed with `N` percent active cells.
b020506b
AT
122
123
124CLI: Simulation Length
125----------------------
126
127If neither of the following two options are passed, the simulation runs as
963282b5 128though `-length 5000` was passed.
b020506b
AT
129
130 - **`-random-length`**: A random length smaller than 10,000 generations but
131 large enough to fill the screen is selected.
132
133 - **`-length N`**: Request `N` generations be simulated on each run.
134
135Note that an upper limit of 10,000 generations is enforced in order to avoid
136`BadAlloc` errors from some X servers. For more details, read
137`WolframAutomata.c` starting around the comment, "The maximum number of
138generations is cell_size dependent. This is a soft limit and may be increased
139if ..."
140
141
6b4b1b56
AT
142CLI: Simulation Speed
143---------------------
144
145If neither of the following two options are passed, the simulation runs as
146though `-delay 25000` was passed.
147
148 - **`-random-delay`**: A random delay is selected, but not truly random. For
149 more details, read `WolframAutomata.c` starting around the comment, "When
150 randomly setting the delay, the problem is to avoid ..."
151
152 - **`-delay N`**: Request `N` microsecond delay between each frame/generation
153 of the simulation. Note that this is only a request; XScreensaver reserves
154 the right to ignore requested values, and of course we execute at the mercy
155 of the kernel's scheduling. In practice, non-absurd values are reasonably
156 well respected.
157
158
b020506b
AT
159CLI: Cell Dimensions
160--------------------
161
162Individual cells may be displayed as any square number of pixels (e.g. 1x1,
1632x2, etc). Increasing the cell size may help with flickering on high DPI
164monitors displaying chaotic rulesets.
165
30934676
AT
166If neither of the following two options are passed, the simulation behaves as
167though `-cell-size 2` was passed.
b020506b 168
30934676
AT
169 - **`-random-cell-size`**: Randomly selects 1, 2, 4, 8, 16, or 32 as the cell
170 size on each reset of the simulation.
b020506b
AT
171
172 - **`-cell-size N`**: Display each individual cell as an `N`x`N` square of
173 pixels on the screen.
174
175
176CLI: Color
177----------
178
179At the moment, the program does not allow the user to specify raw RGB values
180from the command line. Instead, color pairs are selected from `color_list[]`
181in `WolframAutomata.c` by specifying an index (starting from `0`) into this
182array. However, any RGB color the user desires may be added by creating new
183entries in that array (or editing existing entries) and recompiling.
184
185If the following CLI option is not passed, a random color selection is made
186from `color_list[]` at the start of each new simulation run.
187
188 - **`-color-index N`**: Select color pair `N` from `color_list[]` in
189 `WolframAutomata.c`.
190
191Note that the names provided as comments in `color_list[]` are X11 color names.
192
193
194CLI: Admiration
195---------------
196
004edcbf 197When the simulation reaches its end as determined by flags like `-length N` it
b020506b
AT
198will pause for a period of time, allowing the viewer to examine it without
199interference from scrolling. By default, this 'admiration window' is five
200seconds long.
201
202 - **`-admiration-delay N`**: At the end of a simulation, pause for `N`
203 seconds before resetting for the next simulation.
de7de9e7
AT
204
205
206XScreensaver Integration
207========================
208
209In addition to running as a standalone program, WolframAutomata can be
210integrated into the XScreensaver framework.
211
212To accomplish this integration, begin by installing and configuring
213XScreensaver via whatever method is appropriate for your operating system. The
214following instructions assume the filesystem paths used by FreeBSD packages and
215ports; your paths may differ. After XScreensaver installation, ensure all
216pertinent config files are created by running `xscreensaver-demo` and
3181d46a 217configuring XScreensaver for your system.
de7de9e7
AT
218
219After XScreensaver is configured and working on your system, ensure that
004edcbf
AT
220WolframAutomata runs in standalone mode on your system. If you can `make clean run`
221in the `screensavers/hacks/WolframAutomata/` folder and see the hack's visual
de7de9e7
AT
222output, you're ready to move on.
223
224At this point, copy the hack into your XScreensaver hack directory. For
225example, with prerequisite steps spelled out:
226
227 git clone git://git.subgeniuskitty.com/screensavers
228 cd screensavers/hacks/WolframAutomata
229 make clean all
e2ec7b68 230 cp WolframAutomata /usr/local/bin/xscreensaver-hacks/wolframautomata
de7de9e7 231
e2ec7b68 232Now create the file `wolframautomata.xml` wherever your system stores
de7de9e7
AT
233XScreensaver config files and populate it with the contents shown below. For
234example, on FreeBSD:
235
e2ec7b68
AT
236 vi /usr/local/share/xscreensaver/config/wolframautomata.xml
237
238 <?xml version="1.0" encoding="ISO-8859-1"?>
239
240 <screensaver name="wolframautomata" _label="WolframAutomata">
241
242 <command arg="-root"/>
243
5a9f06f2
AT
244 <string id="rule_number" _label="Rule number: " arg="-rule %" />
245 <boolean id="rnd_rule" _label="Random rule" arg-set="-random-rule" />
e2ec7b68 246
5a9f06f2
AT
247 <string id="seed_density" _label="Seed density (%):" arg="-seed-density %" />
248 <boolean id="seed_left" _label="Seed left" arg-set="-seed-left" />
249 <boolean id="seed_center" _label="Seed center" arg-set="-seed-center" />
250 <boolean id="seed_right" _label="Seed right" arg-set="-seed-right" />
e2ec7b68 251
5a9f06f2
AT
252 <string id="length" _label="Length (gen):" arg="-length %" />
253 <boolean id="rnd_length" _label="Random length" arg-set="-random-length" />
e2ec7b68 254
5a9f06f2
AT
255 <string id="delay" _label="Delay (usec):" arg="-delay %" />
256 <boolean id="rnd_delay" _label="Random delay" arg-set="-random-delay" />
e2ec7b68 257
5a9f06f2
AT
258 <string id="cell_size" _label="Cell size (px):" arg="-cell-size %" />
259 <boolean id="rnd_cellsize" _label="Random cell size" arg-set="-random-cell-size" />
e2ec7b68 260
5a9f06f2 261 <string id="color_index" _label="Color index (int):" arg="-color-index %" />
e2ec7b68 262
5a9f06f2 263 <string id="admiration" _label="Admiration (sec):" arg="-admiration-delay %" />
e2ec7b68
AT
264
265 <_description>
266 Displays the time evolution of elementary cellular automata.
267
268 These automata consist of a line of cells, each of which may be either on or
269 off. To ensure every cell has neighbors, the two endpoints of the line connect
270 together, thereby forming a circular universe for the cells to inhabit. This
271 line is drawn horizontally on the screen.
272
273 Over time, this line of cells evolves according to rules, with some cells
274 switching on or off. Each new iteration is drawn below its predecessor,
275 leading the screen to scroll vertically over time.
276
277 The rules which govern the time evolution of this system depend only on the
278 current state of a given cell and the state of its two immediate neighbors.
279 These rules are formalized as Wolfram codes, where the code number is directly
280 convertible into a rule set.
281 </_description>
282 </screensaver>
de7de9e7 283
3181d46a
AT
284The next step integrates WolframAutomata into an individual user's XScreensaver
285config via the file `~/.xscreensaver`. If preferred, it could instead be done
286in the global XScreensaver config.
de7de9e7 287
3181d46a
AT
288In the `~/.xscreensaver` file, create a WolframAutomata entry under the
289`programs:` label in the same list as all the other hacks. Position in the
290list is irrelevant, but ensure you don't paste WolframAutomata's entry into the
291middle of pre-existing, multi-line entries. For context, the example below
292includes a multi-line entry, a GL entry and a plain entry. All that is needed
293is to insert the WolframAutomata line somewhere in the `programs:` list, as
294demonstrated.
de7de9e7
AT
295
296 vi ~/.xscreensaver
297
3181d46a 298 <snip>
de7de9e7 299 programs: \
3181d46a
AT
300 xplanet -vroot -wait 1 -timewarp 400 \
301 -label -origin moon \n\
302 GL: fireflies -root \n\
e2ec7b68 303 wolframautomata -root \n\
3181d46a
AT
304 blitspin -root \n\
305 <snip>
de7de9e7
AT
306
307That's all. Now you can run `xscreensaver-demo` and select WolframAutomata just
308like any other hack.
309
310
311Screen Tearing
312==============
313
314Certain combinations of rules and display settings lead to full screen vertical
315scrolling of alternating light and dark pixels, or other difficult to display
316patterns. If your display doesn't include some type of vertical refresh
317synchronization, such output will look terrible.
318
319If stuck in this situation, changing the output of WolframAutomata to scroll
320horizontally may help, or simply increasing the cell size.
321