Let It Snow In Your Terminal

Copy and paste the commands below into your bash shell to have it "snow" in your terminal. Make sure you have gawk installed. Standard awk will not work due to buffering problems.

clear;while :;do echo $LINES $COLUMNS $(($RANDOM%$COLUMNS));sleep 0.1;done|gawk '{a[$3]=0;for(x in a) {o=a[x];a[x]=a[x]+1;printf "\033[%s;%sH ",o,x;printf "\033[%s;%sH*\033[0;0H",a[x],x;}}'

Note: If you want to put this in a shell script, you'll need to either manually set COLUMNS and LINES to whatever your width and height of your terminal is in characters or 'export COLUMNS LINES' in your shell before running the script. These are not normally in the shell exported environment variables. You can also use stty size to get the values from a script, which is probably the better way anyways for a script.

Below is the same algorithm, but also passing it the unicode snowflake. Its recommended that you increase the font size above 18 to make the snowflake's details visible..

clear;while :;do echo $LINES $COLUMNS $(($RANDOM%$COLUMNS)) $(printf "\u2743\n");sleep 0.1;done|gawk '{a[$3]=0;for(x in a) {o=a[x];a[x]=a[x]+1;printf "\033[%s;%sH ",o,x;printf "\033[%s;%sH%s \033[0;0H",a[x],x,$4;}}'

There are actually a few other snowflakes in Unicode and other characters that are visually interesting. Experiment around with the value of \u2743.

Note for Mac users: You will probably need to install the gawk command via ports or something. Also, I couldn't get the unicode characters to print using the printf that comes installed with Snow Lion (ironically) and the default bash is too old to support it with the builtin printf. You may have to upgrade bash to do this.

climagic home page

Created: 2011-11-28, updated 2012-12-19

blog comments powered by Disqus