Skip to content

Instantly share code, notes, and snippets.

@paradigm
Last active February 26, 2020 03:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paradigm/25d99a79de59c364279afc4ab80994a9 to your computer and use it in GitHub Desktop.
Save paradigm/25d99a79de59c364279afc4ab80994a9 to your computer and use it in GitHub Desktop.
#!/bin/sh
norm_color='\033[2;97m'
high_color='\033[0;97m'
drawing='__
\ \___
\ _ \
\___/
'
order='0,0
1,0
2,1
3,1
4,1
5,1
6,2
6,3
5,3
4,3
3,3
2,3
1,2
0,1'
delay_sec="0.08"
cursor_hide='\033[?25l'
cursor_save='\033[s'
cursor_restore='\033[u'
cursor_left='\033[1D'
draw() {
i="${1}"
color="${2}"
x="$(echo "${order}" | awk -F',' -v"i=${i}" 'NR==i {print $1}')"
y="$(echo "${order}" | awk -F',' -v"i=${i}" 'NR==i {print $2}')"
if [ -n "${color}" ]; then
c="$(echo "${drawing}" | awk -v"x=${x}" -v"y=${y}" 'NR==(y+1) {print substr($0,(x+1),1);exit}')"
else
c=" "
fi
printf "${cursor_restore}"
[ "${x}" -gt 0 ] && printf "\033[${x}C"
[ "${y}" -gt 0 ] && printf "\033[${y}B"
printf "${color}%s${cursor_left}" "${c}"
}
max="$(echo "${order}" | wc -l)"
printf "${cursor_hide}"
clear
printf "${cursor_save}"
printf "\033[4C\033[2B${norm_color}_"
h=$((max/2))
n=$((h-2))
b=0
while :; do
h=$((h+1))
n=$((n+1))
b=$((b+1))
[ "${h}" -gt "${max}" ] && h=1
[ "${n}" -gt "${max}" ] && n=1
[ "${b}" -gt "${max}" ] && b=1
draw "${h}" "${high_color}"
draw "${n}" "${norm_color}"
draw "${b}" ""
sleep "${delay_sec}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment