Sha256: 8bc0fec61292adb30d4897300f81517d8890a60c0eb262583442048d1c53c73e
Contents?: true
Size: 1.36 KB
Versions: 2
Compression:
Stored size: 1.36 KB
Contents
module Facades module SassExt module Color # Check the luminance of color. This differs from lightness as it returns the actual values as 'light' and 'dark' 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 # Tint a color by mixing it with white 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 # Shade a color by mixing it with black 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 # Converts a rgba to hex string, via compass ie_hex_str def rgba_to_hex(color) assert_type color, :Color alpha = (color.alpha * 255).round alphastr = alpha.to_s(16).rjust(2, '0') Sass::Script::String.new("##{alphastr}#{color.send(:hex_str)[1..-1]}".upcase) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
facades-0.1.0 | lib/facades/sass_ext/color.rb |
facades-0.0.7 | lib/facades/sass_ext/color.rb |