Skip to content

Instantly share code, notes, and snippets.

@hungrymedia
Last active December 17, 2015 13:49
Show Gist options
  • Save hungrymedia/5620022 to your computer and use it in GitHub Desktop.
Save hungrymedia/5620022 to your computer and use it in GitHub Desktop.
Snip: Ruby RGB color math
def hover_color(original_hex, percent)
rgb = original_hex.scan /[^#]{2}/
rgb_l = '#'
rgb.each do |h|
dec = (h.to_i(16) * percent).round
component = dec > 255 ? 255 : dec
rgb_l << component.to_s(16).center(2,'0')
end
rgb_l
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment