Added notes on generating screenshots of running hacks.
[screensavers] / hacks / WolframAutomata / screenshot_notes.md

Screenshots for the README were generated by dumping X pixmaps in XPM format, followed by conversion to GIF and integration into animated GIF using ImageMagick.

First, to generate an XPM screenshot on each frame, make the following code modifications to WolframAutomata.c.

Add to top of file:

#include <X11/xpm.h>

Add to struct state:

int framenumber;

In WolframAutomata_init():

state->framenumber = 0;

In WolframAutomata_draw(), toward the end, right before returning:

XWindowAttributes xgwa;
XGetWindowAttributes(state->dpy, state->win, &xgwa);
Pixmap temp = XCreatePixmap(state->dpy, state->win, state->dpy_width, state->dpy_height, xgwa.depth);
XCopyArea(state->dpy, state->evolution_history, temp, state->gc, 0, window_y_offset, state->dpy_width, state->dpy_height, 0, 0);
char * buffer = malloc(29);
snprintf(buffer, 29, "/tmp/wolfram-frame-%05d.xpm", state->framenumber);
XpmWriteFileFromPixmap(state->dpy, buffer, temp, 0, NULL);
state->framenumber++;
XFreePixmap(state->dpy, temp);

Now recompile after adding -lXpm to the linker flags in the Makefile.

Deleting every other frame had negligible visual impact, so all odd number frames were deleted to shrink file size of the resulting animation.

To convert all XPM files in a directory using ImageMagick’s convert, use the following bash snippet:

for f in *.xpm ; do convert "$f" "${f%.xpm}.gif" ; done

To combine GIFs into a single animated GIF, use the following command:

convert -layers OptimizePlus -delay 10x600 wolfram-frame-*.gif -loop 0 wolfram.gif

Check the ImageMagick manual for other -layers options. Some had significant impact on filesize and the manual contains good descriptions of the algorithm behind each.

For setting the replay speed of the animated GIF, note that -delay is of the form ticks-per-frame x ticks-per-second. For example, 10x600 is ten ticks per frame and 600 ticks per second.

Unlike what one might expact, -loop 0 causes the animated GIF to loop and -loop 1 causes it to halt.