snowjob.sh 714 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/bash
  2. LINES=$(tput lines)
  3. COLUMNS=$(tput cols)
  4. declare -A snowflakes
  5. declare -A lastflakes
  6. clear
  7. function move_flake() {
  8. i="$1"
  9. if [ "${snowflakes[$i]}" = "" ] || [ "${snowflakes[$i]}" = "$LINES" ]; then
  10. snowflakes[$i]=0
  11. else
  12. if [ "${lastflakes[$i]}" != "" ]; then
  13. printf "\033[%s;%sH \033[1;1H " ${lastflakes[$i]} $i
  14. fi
  15. fi
  16. printf "\033[%s;%sH\u274$[($RANDOM%6)+3]\033[1;1H" ${snowflakes[$i]} $i
  17. lastflakes[$i]=${snowflakes[$i]}
  18. snowflakes[$i]=$((${snowflakes[$i]}+1))
  19. }
  20. while :
  21. do
  22. i=$(($RANDOM % $COLUMNS))
  23. move_flake $i
  24. for x in "${!lastflakes[@]}"
  25. do
  26. move_flake "$x"
  27. done
  28. sleep 0.1
  29. done