Skip to content

Instantly share code, notes, and snippets.

@anshdivu
Created December 19, 2014 19:52
Show Gist options
  • Save anshdivu/a2349630ed63834b1c31 to your computer and use it in GitHub Desktop.
Save anshdivu/a2349630ed63834b1c31 to your computer and use it in GitHub Desktop.
screen_width = `stty size`.scan(/\d+/)[1].to_i;
snow_char = ["2743".to_i(16)].pack("U*");
# clear screen
puts "\033[2J";
screen = {}; # screen as a 2D array
loop {
# select random column in first row of screen
screen[rand(screen_width)] = 0;
# run snowflakes down the screen
screen.each { |row, col|
screen[row] += 1;
# print snowflake on screen
print "\033[#{col};#{row}H \033[#{screen[row]};#{row}H#{snow_char} \033[0;0H"
};
$stdout.flush;
sleep 0.1
}
@anshdivu
Copy link
Author

# zsh alias
alias snow='ruby ~/let_it_snow.rb'

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