Skip to content

Instantly share code, notes, and snippets.

@flanger001
Forked from mehdi-farsi/make_it_snow.rb
Created January 13, 2023 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flanger001/e72739bf0ad967fd019ff99e1f9194b1 to your computer and use it in GitHub Desktop.
Save flanger001/e72739bf0ad967fd019ff99e1f9194b1 to your computer and use it in GitHub Desktop.
trap("SIGINT") { exit! }
total_width = `stty size`.scan(/\d+/)[1].to_i # terminal width
snokflakes = {}
puts "\033[2J"; # clearing output
loop do
snokflakes[rand(total_width)] = 0
snokflakes.each do |column, row|
snokflakes[column] += 1 # increment row value
print "\033[#{row};#{column}H" + " " # move cursor to [row, column] and replace current ❃ by a space
print "\033[#{row + 1};#{column}H" # move cursor down (row + 1)
print "❃ " # print snowflake
print "\033[0;0H" # move cursor to top/left position (cursor doesn't follow snowflake)
end
sleep 0.1
end
clear_screen = -> { puts "\033[2J" }
trap("SIGINT") do
clear_screen.call
puts "Morpheus: 'Follow me.'"
exit!
end
total_width = `stty size`.scan(/\d+/)[1].to_i # terminal width
chars = {}
eligible_chars = ('a'..'z').to_a + ('1'..'9').to_a
clear_screen.call
loop do
chars[rand(total_width)] = 0
chars.each do |column, row|
chars[column] += 1 # increment row value
print "\033[#{row + 1};#{column}H" # move cursor down (row + 1)
print "#{eligible_chars.sample} " # print random character
print "\033[0;0H" # move cursor to top/left position
end
sleep 0.1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment