Created
December 27, 2017 14:19
-
-
Save gravataLonga/f5e63df9d2efdd6cb4a61d0e636c5680 to your computer and use it in GitHub Desktop.
Snow on Cli
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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*\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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment