Module: Abachrome::ColorMixins::Lighten

Defined in:
lib/abachrome/color_mixins/lighten.rb

Instance Method Summary collapse

Instance Method Details

#darken(amount = 0.1) ⇒ Color

Darkens a color by decreasing its lightness value.

This method is effectively a convenience wrapper around the #lighten method, passing a negative amount value to decrease the lightness instead of increasing it.

Defaults to 0.1 (10% darker).

See Also:



70
71
72
# File 'lib/abachrome/color_mixins/lighten.rb', line 70

def darken(amount = 0.1)
  lighten(-amount)
end

#darken!(amount = 0.1) ⇒ Abachrome::Color

Decreases the lightness value of the color by the specified amount. Modifies the color in place.

Defaults to 0.1 (10% darker).

See Also:



81
82
83
# File 'lib/abachrome/color_mixins/lighten.rb', line 81

def darken!(amount = 0.1)
  lighten!(-amount)
end

#lighten(amount = 0.1) ⇒ Abachrome::Color

Increases the lightness of a color by the specified amount in the OKLab color space. This method works by extracting the L (lightness) component from the OKLab representation of the color and increasing it by the given amount, ensuring the result stays within the valid range of [0, 1].

value between 0 and 1. Defaults to 0.1 (10% increase).



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/abachrome/color_mixins/lighten.rb', line 30

def lighten(amount = 0.1)
  amount = AbcDecimal(amount)
  oklab = to_oklab
  l, a, b = oklab.coordinates

  new_l = l + amount
  new_l = AbcDecimal("1.0") if new_l > 1
  new_l = AbcDecimal("0.0") if new_l.negative?

  Color.new(
    ColorSpace.find(:oklab),
    [new_l, a, b],
    alpha
  )
end

#lighten!(amount = 0.1) ⇒ Abachrome::Color

Increases the lightness of the color by the specified amount and modifies the current color object. This method changes the color in-place, mutating the current object. The color is converted to a lightness-based color space if needed to perform the operation.

between 0 and 1. Default is 0.1 (10% increase).



53
54
55
56
57
58
59
# File 'lib/abachrome/color_mixins/lighten.rb', line 53

def lighten!(amount = 0.1)
  lightened = lighten(amount)
  @color_space = lightened.color_space
  @coordinates = lightened.coordinates
  @alpha = lightened.alpha
  self
end