Module: Chroma::Color::Attributes

Included in:
Chroma::Color
Defined in:
lib/chroma/color/attributes.rb

Overview

Attribute methods for Chroma::Color.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#formatObject (readonly)

Returns the value of attribute format


5
6
7
# File 'lib/chroma/color/attributes.rb', line 5

def format
  @format
end

Instance Method Details

#alphaFloat

Returns the alpha channel value.

Examples:

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

36
37
38
# File 'lib/chroma/color/attributes.rb', line 36

def alpha
  @rgb.a
end

#brightnessFloat

Calculates the brightness.

Examples:

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

47
48
49
# File 'lib/chroma/color/attributes.rb', line 47

def brightness
  (@rgb.r * 299 + @rgb.g * 587 + @rgb.b * 114) / 1000.0
end

#dark?true, false

Determines if the color is dark.

Examples:

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

14
15
16
# File 'lib/chroma/color/attributes.rb', line 14

def dark?
  brightness < 128
end

#light?true, false

Determines if the color is light.

Examples:

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

25
26
27
# File 'lib/chroma/color/attributes.rb', line 25

def light?
  !dark?
end