Added notes on generating screenshots of running hacks.
[screensavers] / hacks / WolframAutomata / screenshot_notes.md
CommitLineData
fde2048e
AT
1Screenshots for the README were generated by dumping X pixmaps in XPM format,
2followed by conversion to GIF and integration into animated GIF using
3ImageMagick.
4
5First, to generate an XPM screenshot on each frame, make the following code
6modifications to `WolframAutomata.c`.
7
8Add to `struct state`:
9
10 int framenumber;
11
12In `WolframAutomata_init()`:
13
14 state->framenumber = 0;
15
16In `WolframAutomata_draw()`, toward the end, right before returning:
17
18 XWindowAttributes xgwa;
19 XGetWindowAttributes(state->dpy, state->win, &xgwa);
20 Pixmap temp = XCreatePixmap(state->dpy, state->win, state->dpy_width, state->dpy_height, xgwa.depth);
21 XCopyArea(state->dpy, state->evolution_history, temp, state->gc, 0, window_y_offset, state->dpy_width, state->dpy_height, 0, 0);
22 char * buffer = malloc(29);
23 snprintf(buffer, 29, "/tmp/wolfram-frame-%05d.xpm", state->framenumber);
24 XpmWriteFileFromPixmap(state->dpy, buffer, temp, 0, NULL);
25 state->framenumber++;
26 XFreePixmap(state->dpy, temp);
27
28Deleting every other frame had negligible visual impact, so all odd number
29frames were deleted to shrink file size of the resulting animation.
30
31To convert all XPM files in a directory using ImageMagick's `convert`, use the
32following bash snippet:
33
34 for f in *.xpm ; do convert "$f" "${f%.xpm}.gif" ; done
35
36To combine GIFs into a single animated GIF, use the following command:
37
38 convert -layers OptimizePlus -delay 10x600 wolfram-frame-*.gif -loop 0 wolfram.gif
39
40Check the ImageMagick manual for other `-layers` options. Some had significant
41impact on filesize and the manual contains good descriptions of the algorithm
42behind each.
43
44For setting the replay speed of the animated GIF, note that `-delay` is of the
45form `ticks-per-frame x ticks-per-second`. For example, `10x600` is ten ticks
46per frame and 600 ticks per second.
47
48Unlike what one might expact, `-loop 0` causes the animated GIF to loop and
49`-loop 1` causes it to halt.