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 | |
f6e3cf3e AT |
13 | switching on or off. Each new application of the rule to the universe is drawn |
14 | on the screen as a new line directly below the previous generation's line, | |
15 | leading the screen to scroll vertically. | |
74edf561 | 16 | |
504a95f7 AT |
17 | Since these are "elementary" cellular automata, the rules which govern the time |
18 | evolution of this system depend only on the current state of a given cell and | |
19 | the state of its two immediate neighbors. These rules are formalized as | |
74edf561 AT |
20 | [Wolfram codes](https://en.wikipedia.org/wiki/Wolfram_code), |
21 | where the code number is directly convertible into a rule set. | |
22 | ||
23 | For example, the following screenshot demonstrates | |
24 | [Rule 110](https://en.wikipedia.org/wiki/Rule_110), itself Turing complete as | |
25 | discussed 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 |
30 | Commandline flags are provided which enable the user to tweak attributes such |
31 | as length and speed of simulation, cell size, rule number, colors, starting | |
32 | seed, and other attributes. For example, the screenshot below depicts Rule 73 | |
33 | with different colors than the Rule 110 screenshot. Like the Rule 110 | |
34 | screenshot, it uses `-cell-size 2` and seeds the simulation with only a single | |
35 | active cell. | |
74edf561 AT |
36 | |
37 | ![Rule 73 Animated Screenshot](/screensavers/.git/blob_plain/HEAD:/hacks/WolframAutomata/screenshot_rule_73.gif) | |
38 | ||
39 | In situations where true randomness would lead to visually unappealing | |
004edcbf | 40 | displays, this program provides random selection from curated lists. As one |
74edf561 AT |
41 | example, to avoid randomly selecting visually indistinguishable colors like |
42 | `dark red` and `brown` to depict on/off cells, the program includes a | |
43 | pre-selected list of color pairs that complement each other and chooses | |
004edcbf | 44 | randomly from this list. |
74edf561 AT |
45 | |
46 | ||
47 | Status | |
48 | ====== | |
49 | ||
50 | Complete. Tested on FreeBSD. | |
51 | ||
52 | Nearly works on Linux. The only problem resides in `WolframAutomata_free()`, | |
53 | where the call to `XFreeGC()` results in a linker error. Commenting that line | |
54 | allows WolframAutomata to build and execute on Linux, but creates a memory leak | |
55 | in the X server, resulting in its eventual termination. | |
56 | ||
57 | ||
58 | Instructions | |
59 | ============ | |
60 | ||
61 | The 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 | ||
64 | If you are running on FreeBSD, simply run one of those three commands. Anywhere | |
65 | else, edit the `Makefile` to suit your environment per the comments included in | |
66 | that file. Note that the `Makefile` assumes a copy of the screenhack library | |
67 | source code is located at `../screenhack/` relative to this directory. | |
68 | ||
f6e3cf3e AT |
69 | For assistance setting `$(DEFINES)` in the `Makefile` on non-FreeBSD platforms, |
70 | consider downloading the XScreensaver source tarball, running `./configure` in | |
71 | the unpacked directory, and examining the resulting `config.h` file. | |
74edf561 AT |
72 | |
73 | Although WolframAutomata can integrate with XScreensaver, the presence of | |
74 | XScreensaver is not strictly required. WolframAutomata will both build and | |
75 | execute using only the included screenhack library. | |
b020506b AT |
76 | |
77 | ||
78 | Command-Line Flags | |
79 | ================== | |
80 | ||
81 | Whenever related options exist, such as the following two rule-selection | |
82 | options, the related options are listed in order of precedence. | |
83 | ||
84 | Where flags instruct the program to make random selections, these selections | |
85 | are re-randomized every time the simulation is reset, such as after a | |
86 | simulation completes or after resizing the window. | |
87 | ||
88 | ||
b020506b AT |
89 | CLI: Rule Selection |
90 | ------------------- | |
91 | ||
92 | If neither of the following two options are passed, rules are randomly selected | |
93 | from `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 |
102 | CLI: Simulation Seed |
103 | -------------------- | |
b020506b | 104 | |
6b4b1b56 AT |
105 | The following seed related CLI flags apply only when using the |
106 | `-true-random-rule` or `-rule N` flags. Without these flags, the program draws | |
107 | rules from `curated_ruleset_list[]` which also includes curated seeds, all of | |
108 | which override any seed related CLI flags. | |
b020506b | 109 | |
6b4b1b56 AT |
110 | If the curated rule list is not in use and none of the following options are |
111 | specified, the starting seed will contain randomly interspersed active/inactive | |
112 | cells 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 | ||
124 | CLI: Simulation Length | |
125 | ---------------------- | |
126 | ||
127 | If neither of the following two options are passed, the simulation runs as | |
963282b5 | 128 | though `-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 | ||
135 | Note 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 | |
138 | generations is cell_size dependent. This is a soft limit and may be increased | |
139 | if ..." | |
140 | ||
141 | ||
6b4b1b56 AT |
142 | CLI: Simulation Speed |
143 | --------------------- | |
144 | ||
145 | If neither of the following two options are passed, the simulation runs as | |
146 | though `-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 |
159 | CLI: Cell Dimensions |
160 | -------------------- | |
161 | ||
162 | Individual cells may be displayed as any square number of pixels (e.g. 1x1, | |
163 | 2x2, etc). Increasing the cell size may help with flickering on high DPI | |
164 | monitors displaying chaotic rulesets. | |
165 | ||
30934676 AT |
166 | If neither of the following two options are passed, the simulation behaves as |
167 | though `-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 | ||
176 | CLI: Color | |
177 | ---------- | |
178 | ||
179 | At the moment, the program does not allow the user to specify raw RGB values | |
180 | from the command line. Instead, color pairs are selected from `color_list[]` | |
181 | in `WolframAutomata.c` by specifying an index (starting from `0`) into this | |
182 | array. However, any RGB color the user desires may be added by creating new | |
183 | entries in that array (or editing existing entries) and recompiling. | |
184 | ||
185 | If the following CLI option is not passed, a random color selection is made | |
186 | from `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 | ||
191 | Note that the names provided as comments in `color_list[]` are X11 color names. | |
192 | ||
193 | ||
194 | CLI: Admiration | |
195 | --------------- | |
196 | ||
004edcbf | 197 | When the simulation reaches its end as determined by flags like `-length N` it |
b020506b AT |
198 | will pause for a period of time, allowing the viewer to examine it without |
199 | interference from scrolling. By default, this 'admiration window' is five | |
200 | seconds 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 | ||
206 | XScreensaver Integration | |
207 | ======================== | |
208 | ||
209 | In addition to running as a standalone program, WolframAutomata can be | |
210 | integrated into the XScreensaver framework. | |
211 | ||
212 | To accomplish this integration, begin by installing and configuring | |
213 | XScreensaver via whatever method is appropriate for your operating system. The | |
214 | following instructions assume the filesystem paths used by FreeBSD packages and | |
215 | ports; your paths may differ. After XScreensaver installation, ensure all | |
216 | pertinent config files are created by running `xscreensaver-demo` and | |
3181d46a | 217 | configuring XScreensaver for your system. |
de7de9e7 AT |
218 | |
219 | After XScreensaver is configured and working on your system, ensure that | |
004edcbf AT |
220 | WolframAutomata runs in standalone mode on your system. If you can `make clean run` |
221 | in the `screensavers/hacks/WolframAutomata/` folder and see the hack's visual | |
de7de9e7 AT |
222 | output, you're ready to move on. |
223 | ||
224 | At this point, copy the hack into your XScreensaver hack directory. For | |
225 | example, 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 | 232 | Now create the file `wolframautomata.xml` wherever your system stores |
de7de9e7 AT |
233 | XScreensaver config files and populate it with the contents shown below. For |
234 | example, 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 |
284 | The next step integrates WolframAutomata into an individual user's XScreensaver |
285 | config via the file `~/.xscreensaver`. If preferred, it could instead be done | |
286 | in the global XScreensaver config. | |
de7de9e7 | 287 | |
3181d46a AT |
288 | In the `~/.xscreensaver` file, create a WolframAutomata entry under the |
289 | `programs:` label in the same list as all the other hacks. Position in the | |
290 | list is irrelevant, but ensure you don't paste WolframAutomata's entry into the | |
291 | middle of pre-existing, multi-line entries. For context, the example below | |
292 | includes a multi-line entry, a GL entry and a plain entry. All that is needed | |
293 | is to insert the WolframAutomata line somewhere in the `programs:` list, as | |
294 | demonstrated. | |
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 | |
307 | That's all. Now you can run `xscreensaver-demo` and select WolframAutomata just | |
308 | like any other hack. | |
309 | ||
310 | ||
311 | Screen Tearing | |
312 | ============== | |
313 | ||
314 | Certain combinations of rules and display settings lead to full screen vertical | |
315 | scrolling of alternating light and dark pixels, or other difficult to display | |
316 | patterns. If your display doesn't include some type of vertical refresh | |
317 | synchronization, such output will look terrible. | |
318 | ||
319 | If stuck in this situation, changing the output of WolframAutomata to scroll | |
320 | horizontally may help, or simply increasing the cell size. | |
321 |