lix2gif: Export Lix animation as animated gif
Requires ImageMagick's convert to cut the source bitmap into pieces, then gifsicle to compose the animation. It's probably possible to do it all with just convert, but I haven't researched further. gifsicle does the job perfectly, the only problem would be that it's an extra dependency.
#!/bin/bash
# Export the first row of a gridded Lix animation file as an animated gif
# with almost-black background. Run without arguments to see usage.
if [ \( $# -lt 3 \) -o \( $# -gt 4 \) ]; then
echo Usage: lix2gif inputfile.png cellWidth cellHeight [numberOfCells]
echo For example: lix2gif factory.T.png 48 64 7
exit 1
fi
tmp="./tempfile-lix2gif-"
src="$1"
fXl="$2" # width ("x-length") of a single frame
fYl="$3" # height ("y-length") of a single frame
imgXl=$(convert "${src}" -ping -format %w info:) # width of entire image
imgYl=$(convert "${src}" -ping -format %h info:) # height of entire image
fNum=$(( (imgXl-1) / (fXl+1) )) # number of frames horizontally in the image
if [ $# -eq 4 ]; then
fNum="$4";
fi
for ((frame = 0; frame < fNum; ++frame)); do
area="${fXl}x${fYl}+$((1 + frame * ( fXl + 1) ))+1"
out="${tmp}"$(printf "%03d" ${frame})
convert "${src}" -crop "${area}" +repage \
-fill "#010101" -opaque "#ff00ff" "${out}.gif"
done
gifsicle --delay=7 --loopcount=0 "${tmp}"*.gif > "${src}.gif"
rm "${tmp}"*
(http://www.lixgame.com/etc/eater-anim.gif)
For example, the script produces the above animation from eater.T.png (http://www.lixgame.com/etc/eater.T.png).
-- Simon