module Pork::Rainbows
Public Instance Methods
msg_pass()
click to toggle source
Calls superclass method
# File lib/pork/extra/rainbows.rb, line 4 def msg_pass @rainbows ||= -1 @rainbows += +1 color256(rainbows(@rainbows), strip_color(super)) end
paint(text)
click to toggle source
# File lib/pork/extra/rainbows.rb, line 10 def paint text @demping ||= -1 @demping += +1 @rainbows = @demping strip_color(text).each_char.map do |c| @rainbows += +1 color256(rainbows(@rainbows), c) end.join end
Private Instance Methods
color256(rgb, text)
click to toggle source
# File lib/pork/extra/rainbows.rb, line 25 def color256 rgb, text "\e[38;5;#{rgb}m#{text}\e[0m" end
rainbows(i)
click to toggle source
# File lib/pork/extra/rainbows.rb, line 29 def rainbows i n = (i%42) / 6.0 r = Math.sin(n + 0*Math::PI/3) * 3 + 3 g = Math.sin(n + 2*Math::PI/3) * 3 + 3 b = Math.sin(n + 4*Math::PI/3) * 3 + 3 16 + 36*r.to_i + 6*g.to_i + b.to_i end
strip_color(text)
click to toggle source
# File lib/pork/extra/rainbows.rb, line 21 def strip_color text text.gsub(/\e\[\d+m/, '') end