public
Last active

Make your terminal snow

  • Download Gist
snowjob.sh
Shell
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
#!/bin/bash
 
LINES=$(tput lines)
COLUMNS=$(tput cols)
 
declare -A snowflakes
declare -A lastflakes
 
clear
 
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\u274$[($RANDOM%6)+3]\033[1;1H" ${snowflakes[$i]} $i
 
lastflakes[$i]=${snowflakes[$i]}
snowflakes[$i]=$((${snowflakes[$i]}+1))
}
 
while :
do
i=$(($RANDOM % $COLUMNS))
 
move_flake $i
 
for x in "${!lastflakes[@]}"
do
move_flake "$x"
done
 
sleep 0.1
done

If your terminal font supports it you can replace * at line 22 with ❄ to make it more festive

Can you make it appear on top of something that's already running?

I named the script as snowjob, and this is the output?
snowjob: 11: Syntax error: "(" unexpected

@allaun What shell are you using? You can replace function move_flake() with function move_flake (removing the parens) and it'll work for you

Nice. Also you can rotate different flake glyphs if you replace * with \u274"$[($RANDOM%6)+3]"

@EmbeddedLinuxGuy That is awesome, thanks!

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.