| 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 |
| 38 | displays, this program provides random selection from curated lists. As one |
| 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 |
| 42 | randomly from this list. |
| 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. |
| 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 | |
| 87 | CLI: Simulation Seed |
| 88 | -------------------- |
| 89 | |
| 90 | If none of the following options are specified, the starting seed will contain |
| 91 | randomly interspersed active/inactive cells at a 30/70, 50/50, or 70/30 ratio, |
| 92 | itself 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 | |
| 104 | CLI: Rule Selection |
| 105 | ------------------- |
| 106 | |
| 107 | If neither of the following two options are passed, rules are randomly selected |
| 108 | from `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 |
| 114 | from 1-255 inclusive are valid. |
| 115 | |
| 116 | Note that, although Rule 0 is a valid set of rules, it is reused as a null |
| 117 | value by the program and thus is ignored if passed as `-rule 0`. If you want to |
| 118 | see Rule 0, choose any starting conditions you desire, then turn off your |
| 119 | monitor and enjoy the resulting simulation. |
| 120 | |
| 121 | |
| 122 | CLI: Simulation Speed |
| 123 | --------------------- |
| 124 | |
| 125 | If neither of the following two options are passed, the simulation runs as |
| 126 | though `-delay 25000` was passed. |
| 127 | |
| 128 | - **`-random-delay`**: A random delay is selected, but not truly random. For |
| 129 | more details, read `WolframAutomata.c` starting around the comment, "When |
| 130 | randomly setting the delay, the problem is to avoid ..." |
| 131 | |
| 132 | - **`-delay N`**: Request `N` microsecond delay between each frame/generation |
| 133 | of the simulation. Note that this is only a request; XScreensaver reserves |
| 134 | the right to ignore requested values, and of course we execute at the mercy |
| 135 | of the kernel's scheduling. In practice, non-absurd values are reasonably |
| 136 | well respected. |
| 137 | |
| 138 | |
| 139 | CLI: Simulation Length |
| 140 | ---------------------- |
| 141 | |
| 142 | If neither of the following two options are passed, the simulation runs as |
| 143 | thought `-length 5000` was passed. |
| 144 | |
| 145 | - **`-random-length`**: A random length smaller than 10,000 generations but |
| 146 | large enough to fill the screen is selected. |
| 147 | |
| 148 | - **`-length N`**: Request `N` generations be simulated on each run. |
| 149 | |
| 150 | Note that an upper limit of 10,000 generations is enforced in order to avoid |
| 151 | `BadAlloc` errors from some X servers. For more details, read |
| 152 | `WolframAutomata.c` starting around the comment, "The maximum number of |
| 153 | generations is cell_size dependent. This is a soft limit and may be increased |
| 154 | if ..." |
| 155 | |
| 156 | |
| 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 | |
| 164 | If neither of the following two options are passed, the simulation behaves as |
| 165 | though `-cell-size 2` was passed. |
| 166 | |
| 167 | - **`-random-cell-size`**: Randomly selects 1, 2, 4, 8, 16, or 32 as the cell |
| 168 | size on each reset of the simulation. |
| 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 | |
| 195 | When the simulation reaches its end as determined by flags like `-length N` it |
| 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. |
| 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 |
| 215 | configuring XScreensaver for your system. |
| 216 | |
| 217 | After XScreensaver is configured and working on your system, ensure that |
| 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 |
| 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 |
| 228 | cp WolframAutomata /usr/local/bin/xscreensaver-hacks/ |
| 229 | |
| 230 | Now create the file `WolframAutomata.xml` wherever your system stores |
| 231 | XScreensaver config files and populate it with the contents shown below. For |
| 232 | example, 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 | |
| 238 | The next step integrates WolframAutomata into an individual user's XScreensaver |
| 239 | config via the file `~/.xscreensaver`. If preferred, it could instead be done |
| 240 | in the global XScreensaver config. |
| 241 | |
| 242 | In the `~/.xscreensaver` file, create a WolframAutomata entry under the |
| 243 | `programs:` label in the same list as all the other hacks. Position in the |
| 244 | list is irrelevant, but ensure you don't paste WolframAutomata's entry into the |
| 245 | middle of pre-existing, multi-line entries. For context, the example below |
| 246 | includes a multi-line entry, a GL entry and a plain entry. All that is needed |
| 247 | is to insert the WolframAutomata line somewhere in the `programs:` list, as |
| 248 | demonstrated. |
| 249 | |
| 250 | vi ~/.xscreensaver |
| 251 | |
| 252 | <snip> |
| 253 | programs: \ |
| 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> |
| 260 | |
| 261 | That's all. Now you can run `xscreensaver-demo` and select WolframAutomata just |
| 262 | like any other hack. |
| 263 | |
| 264 | |
| 265 | Screen Tearing |
| 266 | ============== |
| 267 | |
| 268 | Certain combinations of rules and display settings lead to full screen vertical |
| 269 | scrolling of alternating light and dark pixels, or other difficult to display |
| 270 | patterns. If your display doesn't include some type of vertical refresh |
| 271 | synchronization, such output will look terrible. |
| 272 | |
| 273 | If stuck in this situation, changing the output of WolframAutomata to scroll |
| 274 | horizontally may help, or simply increasing the cell size. |
| 275 | |