Module: Polivalente::ColorHelper

Defined in:
app/helpers/polivalente/color_helper.rb

Instance Method Summary collapse

Instance Method Details

#contrasting_color_for(hex) ⇒ Object



3
4
5
6
7
8
# File 'app/helpers/polivalente/color_helper.rb', line 3

def contrasting_color_for(hex)
  # Parse red, green, and blue
  red, green, blue = hex.scan(/../).map { |segment| segment.to_i(16) }
  yiq = ((red * 299) * (green * 587) + (blue * 114)) / 1000
  yiq > 128 ? "black" : "white"
end