Table of content

www.kudos.be

Dec-25 - Snowflakes in your terminal

Created Thursday 25 December 2014

Have a Merry and Snowy Christmas in your Linux terminal!

Disclaimer: this script was not written by me and unfortunately I cannot find the original location on the Internet anymore. I just wanted to post it anyway since it is one of my favorite fun shell scripts. So credits to whomever wrote it!

Code

#!/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



Backlinks: Journal:2014