factorized script to produce the 3 set of images starting just from north images
[brisk-img.git] / bin / spriter.sh
1 #!/bin/bash
2 #
3 #  Max height in play area 121 px
4 #
5 # set -x
6
7
8 if [ $# -ne 3 -o "$1" = "-h" -o "$1" = "--help" ]; then
9     echo "$0 <folder_in> <suffix> <file_out_without_extension>"
10     exit 1
11 fi
12 fold=$1
13 sfx=$2
14 fou=$3
15
16 w=$(identify -format "%w" ${fold}/00${sfx}.png)
17 h=$(identify -format "%h" ${fold}/00${sfx}.png)
18
19 convert -size $((w * 9))x$((h * 5)) xc:none ${fou}${sfx}_bg.png
20 convert -size $((h * 9))x$((w * 5)) xc:none ${fou}${sfx}_oriz_bg.png
21
22 for direction in "" "_ea" "_we"; do
23     horiz_sfx=""
24     if [ "$direction" != "" ]; then
25         horiz_sfx="_oriz"
26     fi
27     argz="${fou}${sfx}${horiz_sfx}_bg.png"
28
29     for seed in 0 1 2 3 4; do
30         for card in $(seq 0 9); do
31             if [ "$direction" = "" ]; then
32                 x=$(((seed * 2 + card / 5) * w)) 
33                 y=$(((card % 5) * h))
34             else
35                 x=$(((seed * 2 + card / 5) * h)) 
36                 y=$(((card % 5) * w))
37             fi
38
39             fin_no=$(printf "%s/%02d%s.png" "$fold" "$((seed * 10 + card))" "$sfx")
40             fin=$(printf "%s/%02d%s%s.png" "$fold" "$((seed * 10 + card))" "$sfx" "$direction")
41             if [ $seed -lt 4 ]; then
42                 if [ "$direction" == "" ]; then
43                     :
44                 elif [ "$direction" == "_ea" ]; then
45                     convert -rotate 270 "$fin_no" "$fin"
46                 elif [ "$direction" == "_we" ]; then
47                     convert -rotate 90 "$fin_no" "$fin"                
48                 else
49                     exit 1
50                 fi
51             fi
52             
53             argz="$argz $fin -geometry +${x}+${y} -composite "
54             if [ $seed -eq 4 ]; then
55                 break
56             fi
57         done
58     done
59     # full color: argz="$argz ${fou}${sfx}.png"
60     argz="$argz +dither -colors 255 ${fou}${sfx}${direction}.png"
61     convert $argz
62     echo "Created ${fou}${sfx}${direction}.png"
63 done
64
65 rm ${fou}${sfx}_bg.png ${fou}${sfx}_oriz_bg.png ${fold}/[0-3][0-9]${sfx}*.png