Skip to content

Instantly share code, notes, and snippets.

@sontek
Last active April 5, 2024 06:51
Show Gist options
  • Save sontek/1505483 to your computer and use it in GitHub Desktop.
Save sontek/1505483 to your computer and use it in GitHub Desktop.
Make your terminal snow
#!/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
@pwhitdog
Copy link

snowflakes are not coming for me
Screenshot 2023-12-15 at 5 58 26 PM

You cut too much in your snowflake paste. Change line 22 to printf "\033[%s;%sH❄\033[1;1H" ${snowflakes[$i]} $i

@cosmicqbit
Copy link

This is what I get on MacOS iTerm2. Is this supposed to be it! I was expecting SNOW flakes xD.

image

@cosmicqbit
Copy link

With ❄

image

@alaz-aura
Copy link

Screenshot 2023-12-17 at 9 49 22 pm

Thanks the updates everyone, snow has been fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment