-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpokemon-generator
executable file
·136 lines (111 loc) · 3.4 KB
/
pokemon-generator
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash
# vars for you to adjust
PICK_RANGE="1-386"
ICON_LOCATION="./icons"
ANIMATION_LENGTH=16
JUMP_HEIGHT=64
DOUBLE_FINISH_ANIMATION=false
# don't change these pls
TEMP_IMG="bulb.png"
EMPTY_IMG="transparent.png"
OUTPUT="./out"
TEMP_IMG="$OUTPUT/$TEMP_IMG"
EMPTY_IMG="$OUTPUT/$EMPTY_IMG"
if [ "$EUID" -ne 0 ]; then
echo "Please run as root."
exit
fi
while [ -n "$1" ]; do
case "$1" in
-u)
UPDATE_PLY=true
;;
-k)
KEEP_TEMP=true
;;
-p)
KEEP_PREV=true
;;
*)
echo "Option $1 not recognized!"
;;
esac
shift
done
rm -rf "$OUTPUT"
mkdir -p "$OUTPUT"
# calculate parabola vars for jump
VERTEX_X=$(($ANIMATION_LENGTH / 2))
PARAB_A=$(bc -l <<< "scale=2;($JUMP_HEIGHT / ($VERTEX_X ^ 2))")
# get path of pokemon
POKE_NUM="$(shuf -i $PICK_RANGE -n 1)"
printf -v POKE_NUM "%03d" $POKE_NUM
echo $POKE_NUM
echo $POKE_NUM > "$OUTPUT/pokenum.txt"
POKE_PATH="${ICON_LOCATION}/${POKE_NUM}.png"
# resize and trim pokemon image
magick convert "$POKE_PATH" -interpolate Nearest -filter point -background none -resize 128x128 -trim "$TEMP_IMG"
WIDTH="$(magick identify -ping -format '%w' $TEMP_IMG)"
HEIGHT="$(magick identify -ping -format '%h' $TEMP_IMG)"
# create empty canvas
magick convert -size 256x256 xc:none "$EMPTY_IMG"
((OFFSET_W = 128 - $WIDTH / 2))
((OFFSET_H = 128 - $HEIGHT / 2))
# get average color and convert it to hex
test=$(magick convert "$TEMP_IMG" -scale 1x1\! -format "%[fx:int(255*r+.5)],%[fx:int(255*g+.5)],%[fx:int(255*b+.5)]" info:-)
reg=${test//,/" "}
HEX_COLOR=$(printf "0x%02x%02x%02x\n" $reg)
# write .plymouth theme file
cat <<EOT > "$OUTPUT/pokemon.plymouth"
[Plymouth Theme]
Name=Pokemon
Description=Theme with a jumping Pokemon $POKE_NUM sprite
ModuleName=two-step
[two-step]
ImageDir=/usr/share/plymouth/themes/pokemon
HorizontalAlignment=.5
VerticalAlignment=.75
Transition=none
TransitionDuration=0.0
BackgroundStartColor=$HEX_COLOR
BackgroundEndColor=$HEX_COLOR
EOT
# generate frames
for i in $(seq 0 $ANIMATION_LENGTH)
do
# calc jump pos at current frame
C_F=$(bc <<< "((-$PARAB_A * ($i - $VERTEX_X) ^ 2) + $JUMP_HEIGHT) / 1")
((POS_Y = $OFFSET_H - $C_F))
OFFSET="+${OFFSET_W}+${POS_Y}"
printf -v fi "%04d" $i
# put pokemon img on canvas at calculated pos
magick composite -colorspace sRGB -geometry "$OFFSET" "$TEMP_IMG" "$EMPTY_IMG" "${OUTPUT}/throbber-${fi}.png"
cp "${OUTPUT}/throbber-${fi}.png" "${OUTPUT}/animation-${fi}.png"
if [ "$DOUBLE_FINISH_ANIMATION" = true ]; then
((ni = $ANIMATION_LENGTH + $i))
printf -v ni "%04d" $ni
cp "${OUTPUT}/animation-${fi}.png" "${OUTPUT}/animation-${ni}.png"
fi
done
if [ "$KEEP_TEMP" != true ]; then
rm "$TEMP_IMG"
fi
rm "$EMPTY_IMG"
# add other needed files
SPINNER_DIR="/usr/share/plymouth/themes/spinner/"
cp "$SPINNER_DIR/box.png" "$OUTPUT"
cp "$SPINNER_DIR/bullet.png" "$OUTPUT"
cp "$SPINNER_DIR/lock.png" "$OUTPUT"
cp "$SPINNER_DIR/entry.png" "$OUTPUT"
# copy old file if option is given
if [ "$KEEP_PREV" = true ]; then
cp "/usr/share/plymouth/themes/pokemon/pokenum.txt" "$OUTPUT/pokenum-prev.txt"
fi
# copy and apply the theme if option is given
if [ "$UPDATE_PLY" != true ]; then
exit
fi
rm -rf "/usr/share/plymouth/themes/pokemon"
cp -rf "$OUTPUT/" "/usr/share/plymouth/themes/pokemon"
rm -rf "$OUTPUT"
plymouth-set-default-theme -R pokemon