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