One more update to previous two commits. Forgot a '#include'.
[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
8891765b
AT
8Add to top of file:
9
10 #include <X11/xpm.h>
11
fde2048e
AT
12Add to `struct state`:
13
14 int framenumber;
15
16In `WolframAutomata_init()`:
17
18 state->framenumber = 0;
19
20In `WolframAutomata_draw()`, toward the end, right before returning:
21
22 XWindowAttributes xgwa;
23 XGetWindowAttributes(state->dpy, state->win, &xgwa);
24 Pixmap temp = XCreatePixmap(state->dpy, state->win, state->dpy_width, state->dpy_height, xgwa.depth);
25 XCopyArea(state->dpy, state->evolution_history, temp, state->gc, 0, window_y_offset, state->dpy_width, state->dpy_height, 0, 0);
26 char * buffer = malloc(29);
27 snprintf(buffer, 29, "/tmp/wolfram-frame-%05d.xpm", state->framenumber);
28 XpmWriteFileFromPixmap(state->dpy, buffer, temp, 0, NULL);
29 state->framenumber++;
30 XFreePixmap(state->dpy, temp);
31
2f843319
AT
32Now recompile after adding `-lXpm` to the linker flags in the `Makefile`.
33
fde2048e
AT
34Deleting every other frame had negligible visual impact, so all odd number
35frames were deleted to shrink file size of the resulting animation.
36
37To convert all XPM files in a directory using ImageMagick's `convert`, use the
38following bash snippet:
39
40 for f in *.xpm ; do convert "$f" "${f%.xpm}.gif" ; done
41
42To combine GIFs into a single animated GIF, use the following command:
43
44 convert -layers OptimizePlus -delay 10x600 wolfram-frame-*.gif -loop 0 wolfram.gif
45
46Check the ImageMagick manual for other `-layers` options. Some had significant
47impact on filesize and the manual contains good descriptions of the algorithm
48behind each.
49
50For setting the replay speed of the animated GIF, note that `-delay` is of the
51form `ticks-per-frame x ticks-per-second`. For example, `10x600` is ten ticks
52per frame and 600 ticks per second.
53
54Unlike what one might expact, `-loop 0` causes the animated GIF to loop and
55`-loop 1` causes it to halt.