Class: Color::HSL
Instance Method Summary
collapse
Methods inherited from Base
#+, #-, #==, inherited, #initialize, #primary_components, #to_a, #to_s
Constructor Details
This class inherits a constructor from Color::Base
Instance Method Details
#css=(string) ⇒ Object
145
146
147
|
# File 'lib/color.rb', line 145
def css=(string)
self.h, self.s, self.l = RGB.new(string).to_hsl.to_a
end
|
#to_css ⇒ Object
141
142
143
|
# File 'lib/color.rb', line 141
def to_css
to_rgb.to_css
end
|
#to_rgb ⇒ Object
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/color.rb', line 124
def to_rgb
return RGB.new(l, l, l, a) if epsilon(s)
q = l < 0.5 ? l * (1.0 + s) : (l + s) - l * s
p = 2 * l - q
tc = [h + 1.0/3.0, h, h - 1.0/3.0]
tc.map! do |x|
x < 0 ? x + 1.0 :
x > 1.0 ? x - 1.0 : x
end
rgb = tc.map do |tc|
tc < 1.0/6.0 ? p + ((q - p) * 6.0 * tc) :
tc < 3.0/6.0 ? q :
tc < 4.0/6.0 ? p + ((q - p) * 6.0 * (2.0/3.0 - tc)) : p
end
RGB.new(rgb + [a])
end
|