-
Notifications
You must be signed in to change notification settings - Fork 13
/
loading.sh
61 lines (44 loc) · 1.09 KB
/
loading.sh
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
terminal_width=`tput cols`
terminal_height=`tput lines`
index=`od -An -N2 -i /dev/random`
index=$(( index %= 500 ))
URLBASE="http://animals.ivolo.me"
counter=0
increment=1
offset=0
steps=10
calculate_max_steps () {
url=${1}
animal="`curl -s "$url"`"
maxlen=0
export IFS="\n"
for word in $animal; do
len=`expr length "$word"`
if [ $len -gt $maxlen ]
then
maxlen=$len
fi
done
animal_width=$((maxlen - offset))
steps=$(( terminal_width - animal_width))
}
step () {
offset=$((offset + increment))
if [ $(( offset % steps )) -eq 0 ]
then
increment=$(( increment * -1))
terminal_width=`tput cols`
terminal_height=`tput lines`
fi
[ $increment -eq 1 ] && reverse="false" || reverse="true"
[ $counter -eq 0 ] && terminal="false" || terminal="true"
url="$URLBASE/?index=$index&offset=$offset&reverse=$reverse&terminal=$terminal&maxwidth=$terminal_width&maxheight=$terminal_height"
curl -s "$url"
counter=$(( counter + 1))
}
while true
do
step
sleep 0.2
done
echo ""