-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchristmas.sh
165 lines (143 loc) · 2.74 KB
/
christmas.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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# MIT License
# Copyright (c) [2021] [CodeSH]
# 优麒麟团队祝大家圣诞快乐!
# 加载背景音乐
if [ -f "christmas.mp3" ];then
mplayer -loop 0 ./christmas.mp3 < /dev/null > /dev/null 2>1 &
else
wget https://www.ubuntukylin.com/public/mp3/christmas.mp3 -O christmas.mp3 --no-check-certificate;
mplayer -loop 0 ./christmas.mp3 < /dev/null > /dev/null 2>1 &
fi
# 清空屏幕
trap "tput reset; tput cnorm; exit"
clear
# 获取窗口的行数和列数
LINES=$(tput lines)
COLUMNS=$(tput cols)
strTree=''
declare -A snowflakes
declare -A lastflakes
# 渲染几种不同的树
tree1=''
tree2=''
tree3=''
tree4=''
tree5=''
# 生成树
function tree() {
# 接收传进来的参数
flag="$1"
# 每行前面的空格
lineSpace=''
# 初始化树
strTree=''
# 生成树的字符串
for ((i=1; i<$((LINES)); i+=2))
{
lineSpace=''
for ((k=1; k<=$((COLUMNS/2-i)); k++)) {
lineSpace=$lineSpace'\x20'
}
for ((j=1; j<=i*2; j++)) {
if [ $((RANDOM%8)) -lt 3 ];
then
lineSpace=$lineSpace'\033['$((RANDOM%7+30))'mo\033[0m'
else lineSpace=$lineSpace'\033[32m*\033[0m'
fi
}
strTree=$strTree'\n'$lineSpace
}
# 树干以及祝福语
for ((i=1; i<=6; i++))
{
lineSpace=''
for ((j=1; j<=$((COLUMNS/2-5)); j++)) {
lineSpace=$lineSpace'\x20'
}
if [ $i -lt 5 ];
then
strTree=$strTree'\n'$lineSpace'\033[33m*********\033[0m'
fi
if [ $i -eq 5 ];
then
lineSpace=''
for ((j=1; j<=$((COLUMNS/2-8)); j++)) {
lineSpace=$lineSpace'\x20'
}
strTree=$strTree'\n'$lineSpace'Merry Christmas'
fi
if [ $i -eq 6 ];
then
lineSpace=''
for ((j=1; j<=$((COLUMNS/3-5)); j++)) {
lineSpace=$lineSpace'\x20'
}
strTree=$strTree'\n'$lineSpace'Ubuntu Kylin will be with you forever'
fi
}
case "$flag" in
"1")
tree1=$strTree
;;
"2")
tree2=$strTree
;;
"3")
tree3=$strTree
;;
"4")
tree4=$strTree
;;
"5")
tree5=$strTree
;;
esac
}
tree 1
tree 2
tree 3
tree 4
tree 5
# 下雪
function move_flake() {
i="$1"
if [ "${snowflakes[$i]}" = "" ] || [ "${snowflakes[$i]}" = "$LINES" ]; then
snowflakes[$i]=0
else
if [ "${lastflakes[$i]}" != "" ]; then
printf "\033[%s;%sH \033[1;1H " ${lastflakes[$i]} $i
fi
fi
printf "\033[%s;%sH\e[1;30m*\e[0m\033[1;1H" ${snowflakes[$i]} $i
lastflakes[$i]=${snowflakes[$i]}
snowflakes[$i]=$((${snowflakes[$i]}+1))
}
# 疯狂下雪
while :
do
# 每次打印一种树
case "$(($RANDOM%5))" in
"1")
echo -e $tree1
;;
"2")
echo -e $tree2
;;
"3")
echo -e $tree3
;;
"4")
echo -e $tree4
;;
"5")
echo -e $tree5
;;
esac
i=$(($RANDOM % $COLUMNS))
move_flake $i
for x in "${!lastflakes[@]}"
do
move_flake "$x"
done
sleep 0.1
done