Introduction
Introduction Statistics Contact Development Disclaimer Help
add a separate script to generate a gif or tty animation from FEN + moves - che…
git clone git://git.codemadness.org/chess-puzzles
Log
Files
Refs
README
LICENSE
---
commit 3ee1d913ba6bcafbf4647c86d45aaf958954793e
parent 5bf484cc8a074778fe73a54541288119dd207822
Author: Hiltjo Posthuma <[email protected]>
Date: Mon, 22 Jan 2024 19:28:32 +0100
add a separate script to generate a gif or tty animation from FEN + moves
Diffstat:
R gifs.sh -> gifs_for_puzzles.sh | 0
A moves.sh | 75 +++++++++++++++++++++++++++++…
2 files changed, 75 insertions(+), 0 deletions(-)
---
diff --git a/gifs.sh b/gifs_for_puzzles.sh
diff --git a/moves.sh b/moves.sh
@@ -0,0 +1,75 @@
+#!/bin/sh
+# make a list of moves from start to end for each move.
+
+output_tty() {
+ while read -r moves; do
+ clear
+ ./fen -o tty "$fen" "$moves"
+ echo ""
+ ./fen -o pgn "$fen" "$moves"
+ echo ""
+ ./fen -o speak -l "$fen" "$moves"
+ sleep 2
+ done
+}
+
+# create animated gifs for puzzle solutions.
+# Dependencies: ffmpeg, ImageMagick, etc.
+output_gif() {
+ tmppal="$(mktemp '/tmp/palette_XXXXXXXX.png')"
+ tmpdir="$(mktemp -d '/tmp/fen_gif_XXXXXXXX')"
+
+ n=1
+ while read -r moves; do
+ f="$tmpdir/$n.svg"
+ ./fen -o svg "$fen" "$moves" > "$f"
+ test -s "$f" || break
+
+ # initial puzzle state also
+ dest="$tmpdir/$n.png"
+ convert "$f" "$dest"
+
+ n=$((n + 1))
+ done
+
+ # create video / animation.
+
+ # generate palette for gif.
+ rm -f "$tmppal"
+ ffmpeg -loglevel error -stats -i "$tmpdir/%d.png"\
+ -vf palettegen "$tmppal"
+
+ # wait longer for last frame.
+ ffmpeg -loglevel error -stats -framerate 1\
+ -i "$tmpdir/%d.png" \
+ -i "$tmppal" \
+ -lavfi 'tpad=stop_mode=clone:stop_duration=4[v];[v]paletteuse[…
+ -map '[out]' \
+ -f gif \
+ -
+
+ rm -rf "$tmpdir"
+ rm -f "$tmppal"
+}
+
+if [ "$1" = "" ] || [ "$2" = "" ]; then
+ echo "$0 <fen> <moves>" >&2
+ exit 1
+fi
+
+fen="$1"
+m="$2"
+while [ "$m" != "" ]; do
+ prevmoves="$m"
+ echo "$m"
+
+ m="${m% }"
+ m="${m%[a-h][0-9][a-h][0-9]}"
+ m="${m%[qrbnQRBN]}" # possible promotion
+ m="${m% }"
+
+ test "$prevmoves" = "$m" && break # same, break also
+done | \
+sort | \
+output_gif
+#output_tty
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.