calendar/app/helpers/calendars_helper.rb

24 lines
460 B
Ruby

module CalendarsHelper
def self.lighten_color(my_hex, percent)
if my_hex[0] == '#'
my_hex = my_hex[1..-1]
end
comp = ''
rgb = []
batch_size = (my_hex.length/3).ceil
(0...3).each do |i|
rgb << my_hex[batch_size*i ... batch_size*(i+1)]
end
rgb.each do |ch|
tmp = (ch.to_i(16) * (1+percent/100.0)).ceil
if tmp > 255
tmp = 255
end
if tmp < 0
tmp = 0
end
comp += format("%02x", tmp)
end
return '#'+comp
end
end