Module: Sass::Extras::Contrast::Color

Defined in:
lib/sass/extras/contrast.rb

Instance Method Summary collapse

Instance Method Details

#brightnessObject



18
19
20
21
# File 'lib/sass/extras/contrast.rb', line 18

def brightness
  # W3C; Rec. 601 luma
  Utils.sum(Utils.mul(rgb, BRIGHTNESS_COEFS))
end

#brightness_altObject



23
24
25
26
# File 'lib/sass/extras/contrast.rb', line 23

def brightness_alt
  # http://alienryderflex.com/hsp.html
  Math.sqrt(Utils.sum(Utils.mul(Utils.sq(rgb), [0.241, 0.691, 0.068])))
end

#diff(other) ⇒ Object



8
9
10
11
# File 'lib/sass/extras/contrast.rb', line 8

def diff(other)
  # W3C
  Utils.sum(Utils.abs(rgb, other.rgb))
end

#diff_alt(other) ⇒ Object



13
14
15
16
# File 'lib/sass/extras/contrast.rb', line 13

def diff_alt(other)
  # 3D - Sqrt(dr^2+dg^2+db^2)
  Math.sqrt(Utils.sum(Utils.sq(Utils.abs(rgb, other.rgb))))
end

#luminanceObject



28
29
30
31
32
33
# File 'lib/sass/extras/contrast.rb', line 28

def luminance
  # http://www.w3.org/TR/WCAG20/#relativeluminancedef
  norm_rgb = rgb.map { |value| value.to_f / 255 }
  relative_luminance = norm_rgb.map { |v| v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055)**2.4 }
  Utils.sum(Utils.mul(relative_luminance, LUMINANCE_COEFS))
end