module Chroma::Color::Attributes

Attribute methods for {Color}.

Attributes

format[R]

Public Instance Methods

alpha() click to toggle source

Returns the alpha channel value.

@example

'red'.paint.alpha                #=> 1.0
'rgba(0, 0, 0, 0.5)'.paint.alpha #=> 0.5

@return [Float]

# File lib/chroma/color/attributes.rb, line 36
def alpha
  @rgb.a
end
brightness() click to toggle source

Calculates the brightness.

@example

'red'.paint.brightness    #=> 76.245
'yellow'.paint.brightness #=> 225.93

@return [Float]

# File lib/chroma/color/attributes.rb, line 47
def brightness
  (@rgb.r * 299 + @rgb.g * 587 + @rgb.b * 114) / 1000.0
end
dark?() click to toggle source

Determines if the color is dark.

@example

'red'.paint.dark?    #=> true
'yellow'.paint.dark? #=> false

@return [true, false]

# File lib/chroma/color/attributes.rb, line 14
def dark?
  brightness < 128
end
light?() click to toggle source

Determines if the color is light.

@example

'red'.paint.light?    #=> false
'yellow'.paint.light? #=> true

@return [true, false]

# File lib/chroma/color/attributes.rb, line 25
def light?
  !dark?
end

Private Instance Methods

rounded_alpha() click to toggle source
# File lib/chroma/color/attributes.rb, line 53
def rounded_alpha
  @rounded_alpha ||= (alpha * 100).round / 100.0
end