moves.sh - chess-puzzles - chess puzzle book generator
HTML git clone git://git.codemadness.org/chess-puzzles
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
moves.sh (1592B)
---
1 #!/bin/sh
2 # make a list of moves from start to end for each move.
3 # writes output to stdout.
4
5 # old deprecated command: gives a warning on some systems.
6 #convert="convert"
7 convert="magick"
8
9 # output moves to tty with some delay.
10 # Show PGN and human speech-like text for the moves.
11 output_tty() {
12 while read -r moves; do
13 clear
14 ./fen -o tty "$fen" "$moves"
15 echo ""
16 ./fen -o pgn "$fen" "$moves"
17 echo ""
18 ./fen -o speak -l "$fen" "$moves"
19 sleep 2
20 done
21 }
22
23 # create an animated gif.
24 # Dependencies: ffmpeg, ImageMagick, etc.
25 output_gif() {
26 tmppal="$(mktemp '/tmp/palette_XXXXXXXX.png')"
27 tmpdir="$(mktemp -d '/tmp/fen_gif_XXXXXXXX')"
28
29 n=1
30 while read -r moves; do
31 f="$tmpdir/$n.svg"
32 ./fen -o svg "$fen" "$moves" > "$f"
33 test -s "$f" || break
34
35 # DEBUG
36 #printf 'Processing moves: %s\n' "$moves" >&2
37
38 dest="$tmpdir/$n.png"
39 $convert "$f" "$dest"
40
41 n=$((n + 1))
42 done
43
44 # generate palette for gif.
45 rm -f "$tmppal"
46 ffmpeg -loglevel error -stats -i "$tmpdir/%d.png"\
47 -vf palettegen "$tmppal"
48
49 # create video / animation.
50 # wait longer for last frame.
51 ffmpeg -loglevel error -stats -framerate 1\
52 -i "$tmpdir/%d.png" \
53 -i "$tmppal" \
54 -lavfi 'tpad=stop_mode=clone:stop_duration=4[v];[v]paletteuse[out]' \
55 -map '[out]' \
56 -f gif \
57 -
58
59 rm -rf "$tmpdir"
60 rm -f "$tmppal"
61 }
62
63 if [ "$1" = "" ] || [ "$2" = "" ]; then
64 echo "$0 <fen> <moves>" >&2
65 exit 1
66 fi
67
68 fen="$1"
69 m="$2"
70 while [ "$m" != "" ]; do
71 prevmoves="$m"
72 echo "$m"
73
74 m="${m% }"
75 m="${m%[^ ]*}"
76 m="${m% }"
77
78 test "$prevmoves" = "$m" && break # same, break also
79 done | \
80 sort | \
81 output_gif
82
83 #output_tty