Class: RubyXL::ColorConvenienceClasses::HlsColor

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyXL/convenience_methods/color.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#aObject

Returns the value of attribute a.



82
83
84
# File 'lib/rubyXL/convenience_methods/color.rb', line 82

def a
  @a
end

#hObject

Returns the value of attribute h.



82
83
84
# File 'lib/rubyXL/convenience_methods/color.rb', line 82

def h
  @h
end

#lObject

Returns the value of attribute l.



82
83
84
# File 'lib/rubyXL/convenience_methods/color.rb', line 82

def l
  @l
end

#sObject

Returns the value of attribute s.



82
83
84
# File 'lib/rubyXL/convenience_methods/color.rb', line 82

def s
  @s
end

Instance Method Details

#apply_tint(tint) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
# File 'lib/rubyXL/convenience_methods/color.rb', line 140

def apply_tint(tint)
  return self if tint.nil? || tint == 0

  if tint < 0 then
    self.l = l * (1.0 + tint);
  else
    self.l = l * (1.0 - tint) + tint;
  end

  self
end

#to_rgbObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/rubyXL/convenience_methods/color.rb', line 84

def to_rgb
  rgb_color = RgbColor.new

  r = g = b = l

  if s != 0 then
    t1 = nil

    if l < 0.5 then
      t1 = l * (1.0 + s)
    else
      t1 = l + s - (l * s)
    end

    t2 = 2.0 * l - t1;
    h = self.h / 360.0

    t_r = h + (1.0 / 3.0)
    r = set_color(t1, t2, t_r)

    t_g = h;
    g = set_color(t1, t2, t_g)

    t_b = h - (1.0 / 3.0);
    b = set_color(t1, t2, t_b)
  end

  rgb_color.r = (r * 255).round(0).to_i
  rgb_color.g = (g * 255).round(0).to_i
  rgb_color.b = (b * 255).round(0).to_i

  rgb_color.a = (a * 255).round(0).to_i

  rgb_color
end