INNER CODE UNIT · Ruby
red
busyloop/lolcat · lib/lolcat/lol.rb:37
red = Math.sin(freq*i + 0) * 127 + 128
green = Math.sin(freq*i + 2*Math::PI/3) * 127 + 128
blue = Math.sin(freq*i + 4*Math::PI/3) * 127 + 128
"#%02X%02X%02X" % [ red, green, blue ]
end
def self.cat(fd, opts={})
@os = opts[:os]
print "\e[?25l" if opts[:animate]
while true do
buf = ''
begin
begin
buf += fd.sysread(4096)
invalid_encoding = !buf.dup.force_encoding(fd.external_encoding).valid_encoding?
end while invalid_encoding or buf.match(INCOMPLETE_ESCAPE)
rescue EOFError
break