Commit | Line | Data |
---|---|---|
fde2048e AT |
1 | Screenshots for the README were generated by dumping X pixmaps in XPM format, |
2 | followed by conversion to GIF and integration into animated GIF using | |
3 | ImageMagick. | |
4 | ||
5 | First, to generate an XPM screenshot on each frame, make the following code | |
6 | modifications to `WolframAutomata.c`. | |
7 | ||
8 | Add to `struct state`: | |
9 | ||
10 | int framenumber; | |
11 | ||
12 | In `WolframAutomata_init()`: | |
13 | ||
14 | state->framenumber = 0; | |
15 | ||
16 | In `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 |
28 | Now recompile after adding `-lXpm` to the linker flags in the `Makefile`. |
29 | ||
fde2048e AT |
30 | Deleting every other frame had negligible visual impact, so all odd number |
31 | frames were deleted to shrink file size of the resulting animation. | |
32 | ||
33 | To convert all XPM files in a directory using ImageMagick's `convert`, use the | |
34 | following bash snippet: | |
35 | ||
36 | for f in *.xpm ; do convert "$f" "${f%.xpm}.gif" ; done | |
37 | ||
38 | To 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 | ||
42 | Check the ImageMagick manual for other `-layers` options. Some had significant | |
43 | impact on filesize and the manual contains good descriptions of the algorithm | |
44 | behind each. | |
45 | ||
46 | For setting the replay speed of the animated GIF, note that `-delay` is of the | |
47 | form `ticks-per-frame x ticks-per-second`. For example, `10x600` is ten ticks | |
48 | per frame and 600 ticks per second. | |
49 | ||
50 | Unlike what one might expact, `-loop 0` causes the animated GIF to loop and | |
51 | `-loop 1` causes it to halt. |