Updated WolframAutomata's rule related CLI flags to match 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
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
87CLI: Simulation Seed
88--------------------
89
90If none of the following options are specified, the starting seed will contain
91randomly interspersed active/inactive cells at a 30/70, 50/50, or 70/30 ratio,
92itself also randomly selected.
93
94 - **`-seed-left`**: Seeds a single active cell on the left side of the
95 display. All other cells are inactive.
96
97 - **`-seed-center`**: As above, but in the center.
98
99 - **`-seed-right`**: As above, but on the right side.
100
101 - **`-seed-density N`**: Generates random seed with `N` percent active cells.
102
103
104CLI: Rule Selection
105-------------------
106
107If neither of the following two options are passed, rules are randomly selected
108from `curated_ruleset_list[]` in `WolframAutomata.c`.
109
110 - **`-true-random-rule`**: Select a rule completely at random, NOT randomly
111 from a curated list. Note that many rules are visually uninteresting.
112
113 - **`-rule N`**: Select a specific rule where `N` is a Wolfram number. Values
89ff0c45 114 from 0-255 inclusive are valid.
b020506b
AT
115
116
117CLI: Simulation Speed
118---------------------
119
120If neither of the following two options are passed, the simulation runs as
121though `-delay 25000` was passed.
122
123 - **`-random-delay`**: A random delay is selected, but not truly random. For
124 more details, read `WolframAutomata.c` starting around the comment, "When
125 randomly setting the delay, the problem is to avoid ..."
126
127 - **`-delay N`**: Request `N` microsecond delay between each frame/generation
128 of the simulation. Note that this is only a request; XScreensaver reserves
129 the right to ignore requested values, and of course we execute at the mercy
130 of the kernel's scheduling. In practice, non-absurd values are reasonably
131 well respected.
132
133
134CLI: Simulation Length
135----------------------
136
137If neither of the following two options are passed, the simulation runs as
138thought `-length 5000` was passed.
139
140 - **`-random-length`**: A random length smaller than 10,000 generations but
141 large enough to fill the screen is selected.
142
143 - **`-length N`**: Request `N` generations be simulated on each run.
144
145Note that an upper limit of 10,000 generations is enforced in order to avoid
146`BadAlloc` errors from some X servers. For more details, read
147`WolframAutomata.c` starting around the comment, "The maximum number of
148generations is cell_size dependent. This is a soft limit and may be increased
149if ..."
150
151
152CLI: Cell Dimensions
153--------------------
154
155Individual cells may be displayed as any square number of pixels (e.g. 1x1,
1562x2, etc). Increasing the cell size may help with flickering on high DPI
157monitors displaying chaotic rulesets.
158
30934676
AT
159If neither of the following two options are passed, the simulation behaves as
160though `-cell-size 2` was passed.
b020506b 161
30934676
AT
162 - **`-random-cell-size`**: Randomly selects 1, 2, 4, 8, 16, or 32 as the cell
163 size on each reset of the simulation.
b020506b
AT
164
165 - **`-cell-size N`**: Display each individual cell as an `N`x`N` square of
166 pixels on the screen.
167
168
169CLI: Color
170----------
171
172At the moment, the program does not allow the user to specify raw RGB values
173from the command line. Instead, color pairs are selected from `color_list[]`
174in `WolframAutomata.c` by specifying an index (starting from `0`) into this
175array. However, any RGB color the user desires may be added by creating new
176entries in that array (or editing existing entries) and recompiling.
177
178If the following CLI option is not passed, a random color selection is made
179from `color_list[]` at the start of each new simulation run.
180
181 - **`-color-index N`**: Select color pair `N` from `color_list[]` in
182 `WolframAutomata.c`.
183
184Note that the names provided as comments in `color_list[]` are X11 color names.
185
186
187CLI: Admiration
188---------------
189
004edcbf 190When the simulation reaches its end as determined by flags like `-length N` it
b020506b
AT
191will pause for a period of time, allowing the viewer to examine it without
192interference from scrolling. By default, this 'admiration window' is five
193seconds long.
194
195 - **`-admiration-delay N`**: At the end of a simulation, pause for `N`
196 seconds before resetting for the next simulation.
de7de9e7
AT
197
198
199XScreensaver Integration
200========================
201
202In addition to running as a standalone program, WolframAutomata can be
203integrated into the XScreensaver framework.
204
205To accomplish this integration, begin by installing and configuring
206XScreensaver via whatever method is appropriate for your operating system. The
207following instructions assume the filesystem paths used by FreeBSD packages and
208ports; your paths may differ. After XScreensaver installation, ensure all
209pertinent config files are created by running `xscreensaver-demo` and
3181d46a 210configuring XScreensaver for your system.
de7de9e7
AT
211
212After XScreensaver is configured and working on your system, ensure that
004edcbf
AT
213WolframAutomata runs in standalone mode on your system. If you can `make clean run`
214in the `screensavers/hacks/WolframAutomata/` folder and see the hack's visual
de7de9e7
AT
215output, you're ready to move on.
216
217At this point, copy the hack into your XScreensaver hack directory. For
218example, with prerequisite steps spelled out:
219
220 git clone git://git.subgeniuskitty.com/screensavers
221 cd screensavers/hacks/WolframAutomata
222 make clean all
223 cp WolframAutomata /usr/local/bin/xscreensaver-hacks/
224
225Now create the file `WolframAutomata.xml` wherever your system stores
226XScreensaver config files and populate it with the contents shown below. For
227example, on FreeBSD:
228
229 vi /usr/local/share/xscreensaver/config/WolframAutomata.xml
230
231 TODO: Finish writing this file after the command line options are finalized.
232
3181d46a
AT
233The next step integrates WolframAutomata into an individual user's XScreensaver
234config via the file `~/.xscreensaver`. If preferred, it could instead be done
235in the global XScreensaver config.
de7de9e7 236
3181d46a
AT
237In the `~/.xscreensaver` file, create a WolframAutomata entry under the
238`programs:` label in the same list as all the other hacks. Position in the
239list is irrelevant, but ensure you don't paste WolframAutomata's entry into the
240middle of pre-existing, multi-line entries. For context, the example below
241includes a multi-line entry, a GL entry and a plain entry. All that is needed
242is to insert the WolframAutomata line somewhere in the `programs:` list, as
243demonstrated.
de7de9e7
AT
244
245 vi ~/.xscreensaver
246
3181d46a 247 <snip>
de7de9e7 248 programs: \
3181d46a
AT
249 xplanet -vroot -wait 1 -timewarp 400 \
250 -label -origin moon \n\
251 GL: fireflies -root \n\
252 WolframAutomata -root \n\
253 blitspin -root \n\
254 <snip>
de7de9e7
AT
255
256That's all. Now you can run `xscreensaver-demo` and select WolframAutomata just
257like any other hack.
258
259
260Screen Tearing
261==============
262
263Certain combinations of rules and display settings lead to full screen vertical
264scrolling of alternating light and dark pixels, or other difficult to display
265patterns. If your display doesn't include some type of vertical refresh
266synchronization, such output will look terrible.
267
268If stuck in this situation, changing the output of WolframAutomata to scroll
269horizontally may help, or simply increasing the cell size.
270