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