Cleaned up CLI flags for cell size in WolframAutomata source code and 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
38displays, this program provides random selection from curated lists. For
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
42randomly from this list when the `-random-color` flag is passed. Similarly, to
43avoid the visually uninteresting rules like rule 0, a rule which simply turns
44every cell off and keeps it off, the program includes a list of rulesets and
45starting seeds which are visually appealing, selecting randomly from this list
46when the `-random-rule` flag is passed.
47
48
49Status
50======
51
52Complete. Tested on FreeBSD.
53
54Nearly works on Linux. The only problem resides in `WolframAutomata_free()`,
55where the call to `XFreeGC()` results in a linker error. Commenting that line
56allows WolframAutomata to build and execute on Linux, but creates a memory leak
57in the X server, resulting in its eventual termination.
58
59
60Instructions
61============
62
63The included `Makefile` includes targets for `make all` to build the hack,
64`make clean` to delete any build detritus, and `make run` to execute the hack.
65
66If you are running on FreeBSD, simply run one of those three commands. Anywhere
67else, edit the `Makefile` to suit your environment per the comments included in
68that file. Note that the `Makefile` assumes a copy of the screenhack library
69source code is located at `../screenhack/` relative to this directory.
70
71For assistance setting `$(DEFINES)` on non-FreeBSD platforms, consider
72downloading the XScreensaver source tarball, running `./configure` in the
73unpacked directory, and examining the resulting `config.h` file.
74
75Although WolframAutomata can integrate with XScreensaver, the presence of
76XScreensaver is not strictly required. WolframAutomata will both build and
77execute using only the included screenhack library.
b020506b
AT
78
79
80Command-Line Flags
81==================
82
83Whenever related options exist, such as the following two rule-selection
84options, the related options are listed in order of precedence.
85
86Where flags instruct the program to make random selections, these selections
87are re-randomized every time the simulation is reset, such as after a
88simulation completes or after resizing the window.
89
90
91CLI: Simulation Seed
92--------------------
93
94If none of the following options are specified, the starting seed will contain
95randomly interspersed active/inactive cells at a 30/70, 50/50, or 70/30 ratio,
96itself also randomly selected.
97
98 - **`-seed-left`**: Seeds a single active cell on the left side of the
99 display. All other cells are inactive.
100
101 - **`-seed-center`**: As above, but in the center.
102
103 - **`-seed-right`**: As above, but on the right side.
104
105 - **`-seed-density N`**: Generates random seed with `N` percent active cells.
106
107
108CLI: Rule Selection
109-------------------
110
111If neither of the following two options are passed, rules are randomly selected
112from `curated_ruleset_list[]` in `WolframAutomata.c`.
113
114 - **`-true-random-rule`**: Select a rule completely at random, NOT randomly
115 from a curated list. Note that many rules are visually uninteresting.
116
117 - **`-rule N`**: Select a specific rule where `N` is a Wolfram number. Values
118 from 1-255 inclusive are valid.
119
120Note that, although Rule 0 is a valid set of rules, it is reused as a null
121value by the program and thus is ignored if passed as `-rule 0`. If you want to
122see Rule 0, choose any starting conditions you desire, then turn off your
123monitor and enjoy the resulting simulation.
124
125
126CLI: Simulation Speed
127---------------------
128
129If neither of the following two options are passed, the simulation runs as
130though `-delay 25000` was passed.
131
132 - **`-random-delay`**: A random delay is selected, but not truly random. For
133 more details, read `WolframAutomata.c` starting around the comment, "When
134 randomly setting the delay, the problem is to avoid ..."
135
136 - **`-delay N`**: Request `N` microsecond delay between each frame/generation
137 of the simulation. Note that this is only a request; XScreensaver reserves
138 the right to ignore requested values, and of course we execute at the mercy
139 of the kernel's scheduling. In practice, non-absurd values are reasonably
140 well respected.
141
142
143CLI: Simulation Length
144----------------------
145
146If neither of the following two options are passed, the simulation runs as
147thought `-length 5000` was passed.
148
149 - **`-random-length`**: A random length smaller than 10,000 generations but
150 large enough to fill the screen is selected.
151
152 - **`-length N`**: Request `N` generations be simulated on each run.
153
154Note that an upper limit of 10,000 generations is enforced in order to avoid
155`BadAlloc` errors from some X servers. For more details, read
156`WolframAutomata.c` starting around the comment, "The maximum number of
157generations is cell_size dependent. This is a soft limit and may be increased
158if ..."
159
160
161CLI: Cell Dimensions
162--------------------
163
164Individual cells may be displayed as any square number of pixels (e.g. 1x1,
1652x2, etc). Increasing the cell size may help with flickering on high DPI
166monitors displaying chaotic rulesets.
167
30934676
AT
168If neither of the following two options are passed, the simulation behaves as
169though `-cell-size 2` was passed.
b020506b 170
30934676
AT
171 - **`-random-cell-size`**: Randomly selects 1, 2, 4, 8, 16, or 32 as the cell
172 size on each reset of the simulation.
b020506b
AT
173
174 - **`-cell-size N`**: Display each individual cell as an `N`x`N` square of
175 pixels on the screen.
176
177
178CLI: Color
179----------
180
181At the moment, the program does not allow the user to specify raw RGB values
182from the command line. Instead, color pairs are selected from `color_list[]`
183in `WolframAutomata.c` by specifying an index (starting from `0`) into this
184array. However, any RGB color the user desires may be added by creating new
185entries in that array (or editing existing entries) and recompiling.
186
187If the following CLI option is not passed, a random color selection is made
188from `color_list[]` at the start of each new simulation run.
189
190 - **`-color-index N`**: Select color pair `N` from `color_list[]` in
191 `WolframAutomata.c`.
192
193Note that the names provided as comments in `color_list[]` are X11 color names.
194
195
196CLI: Admiration
197---------------
198
199When the simulation reaches its end as determined by flags like `-length N`, it
200will pause for a period of time, allowing the viewer to examine it without
201interference from scrolling. By default, this 'admiration window' is five
202seconds long.
203
204 - **`-admiration-delay N`**: At the end of a simulation, pause for `N`
205 seconds before resetting for the next simulation.
de7de9e7
AT
206
207
208XScreensaver Integration
209========================
210
211In addition to running as a standalone program, WolframAutomata can be
212integrated into the XScreensaver framework.
213
214To accomplish this integration, begin by installing and configuring
215XScreensaver via whatever method is appropriate for your operating system. The
216following instructions assume the filesystem paths used by FreeBSD packages and
217ports; your paths may differ. After XScreensaver installation, ensure all
218pertinent config files are created by running `xscreensaver-demo` and
219configuring it for your system.
220
221After XScreensaver is configured and working on your system, ensure that
222WolframAutomata runs in standalone mode on your system. If you can `make clean
223run` in the `screensavers/hacks/WolframAutomata/` folder and see the hack's
224output, you're ready to move on.
225
226At this point, copy the hack into your XScreensaver hack directory. For
227example, with prerequisite steps spelled out:
228
229 git clone git://git.subgeniuskitty.com/screensavers
230 cd screensavers/hacks/WolframAutomata
231 make clean all
232 cp WolframAutomata /usr/local/bin/xscreensaver-hacks/
233
234Now create the file `WolframAutomata.xml` wherever your system stores
235XScreensaver config files and populate it with the contents shown below. For
236example, on FreeBSD:
237
238 vi /usr/local/share/xscreensaver/config/WolframAutomata.xml
239
240 TODO: Finish writing this file after the command line options are finalized.
241
242The final step integrates WolframAutomata into an individual users's
243XScreensaver framework. If preferred, it could instead be done in the global
244XScreensaver config.
245
246Add the WolframAutomata entry under the `programs:` label, in the same list as
247all the other hacks. Position in the list is irrelevant, but ensure you don't
248paste WolframAutomata's entry into the middle of pre-existing, multi-line
249entries.
250
251 vi ~/.xscreensaver
252
253 programs: \
254 WolframAutomata -root -party-mode \n\
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