Added additional note to previous commit. Forgot to mention linker flags.
[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
2f843319
AT
28Now recompile after adding `-lXpm` to the linker flags in the `Makefile`.
29
fde2048e
AT
30Deleting every other frame had negligible visual impact, so all odd number
31frames were deleted to shrink file size of the resulting animation.
32
33To convert all XPM files in a directory using ImageMagick's `convert`, use the
34following bash snippet:
35
36 for f in *.xpm ; do convert "$f" "${f%.xpm}.gif" ; done
37
38To combine GIFs into a single animated GIF, use the following command:
39
40 convert -layers OptimizePlus -delay 10x600 wolfram-frame-*.gif -loop 0 wolfram.gif
41
42Check the ImageMagick manual for other `-layers` options. Some had significant
43impact on filesize and the manual contains good descriptions of the algorithm
44behind each.
45
46For setting the replay speed of the animated GIF, note that `-delay` is of the
47form `ticks-per-frame x ticks-per-second`. For example, `10x600` is ten ticks
48per frame and 600 ticks per second.
49
50Unlike what one might expact, `-loop 0` causes the animated GIF to loop and
51`-loop 1` causes it to halt.