Module: Facades::SassExtensions::Color
- Defined in:
- lib/facades/sass_extensions/color.rb
Instance Method Summary collapse
-
#luminance(color) ⇒ Object
Check the luminance of color.
-
#shade(color, dilution = Sass::Script::Number.new(50)) ⇒ Object
Shade a color by mixing it with black.
-
#tint(color, dilution = Sass::Script::Number.new(50)) ⇒ Object
Tint a color by mixing it with white.
Instance Method Details
#luminance(color) ⇒ Object
Check the luminance of color. This differs from lightness as it returns the actual values as ‘light’ and ‘dark’
6 7 8 9 10 |
# File 'lib/facades/sass_extensions/color.rb', line 6 def luminance(color) assert_type color, :Color result = ((color.red * 299) + (color.green * 587) + (color.blue * 114) / 1000) Sass::Script::String.new( result >= 160 ? 'light' : 'dark') end |
#shade(color, dilution = Sass::Script::Number.new(50)) ⇒ Object
Shade a color by mixing it with black
21 22 23 24 25 26 |
# File 'lib/facades/sass_extensions/color.rb', line 21 def shade(color, dilution = Sass::Script::Number.new(50)) assert_type color, :Color black = Sass::Script::Color.new([0, 0, 0, 1]) assert_type dilution, :Number mix(color, black, Sass::Script::Number.new(100 - dilution.value)) end |
#tint(color, dilution = Sass::Script::Number.new(50)) ⇒ Object
Tint a color by mixing it with white
13 14 15 16 17 18 |
# File 'lib/facades/sass_extensions/color.rb', line 13 def tint(color, dilution = Sass::Script::Number.new(50)) assert_type color, :Color white = Sass::Script::Color.new([255, 255, 255, 1]) assert_type dilution, :Number mix(color, white, Sass::Script::Number.new(100 - dilution.value)) end |