Skip to content

Instantly share code, notes, and snippets.

@padde

padde/stars.rb

Last active Jan 29, 2016
Embed
What would you like to do?
Colored stars (dabbling with ANSI escape codes)
lines = `tput lines`.to_i
cols = `tput cols`.to_i
# hide cursor
print "\e[?25l"
# clear screen
print "\e[2J"
at_exit do
# show cursor
puts "\e[?25h"
# clear screen
print "\e[2J"
# reset color
print "\e[0m"
end
50000.times do |i|
line = rand 1..lines
col = rand 1..cols
r = rand 0..255
g = rand 0..255
b = rand 0..255
# print "\e[48;2;%d;%d;%dm" % [r,g,b]
print "\e[38;2;%d;%d;%dm" % [255-r,255-g,255-b]
print "\e[#{line};#{col}f*"
sleep 0.001
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment