Skip to content

Instantly share code, notes, and snippets.

@artm
Created December 20, 2012 09:04
Show Gist options
  • Save artm/4344001 to your computer and use it in GitHub Desktop.
Save artm/4344001 to your computer and use it in GitHub Desktop.
remake with uglified ruby oneliner (ruby 1.8.x and 1.9.x compatible)
# reverse engineering gawk code
{
rnd_column = $3; # comes from bash $(($RANDOM%$COLUMNS))
snow = $4; # comes from bash $(printf "\u2743\n")
snow_progress[ rnd_column ] = 0;
for(row in snow_progress) {
old_col = snow_progress[row];
snow_progress[row] = snow_progress[row] + 1;
# erase snowflake at previous position
printf "\033[%s;%sH ",old_col,row;
# draw snowflake at new position
printf "\033[%s;%sH%s \033[0;0H",snow_progress[row],row, snow;
}
}
C=`stty size`.scan(/\d+/)[1].to_i;S=["2743".to_i(16)].pack("U*");a={};puts "\033[2J";loop{a[rand(C)]=0;a.each{|x,o|;a[x]+=1;print "\033[#{o};#{x}H \033[#{a[x]};#{x}H#{S} \033[0;0H"};$stdout.flush;sleep 0.1}
ruby -e 'C=`stty size`.scan(/\d+/)[1].to_i;S=["2743".to_i(16)].pack("U*");a={};puts "\033[2J";loop{a[rand(C)]=0;a.each{|x,o|;a[x]+=1;print "\033[#{o};#{x}H \033[#{a[x]};#{x}H#{S} \033[0;0H"};$stdout.flush;sleep 0.1}'
@k0a1a
Copy link

k0a1a commented Feb 9, 2013

cool rework!
and just to mention the original: http://climagic.org/coolstuff/let-it-snow.html

@artm
Copy link
Author

artm commented Feb 10, 2013

:-) I'll let them know :-)

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