Skip to content

Instantly share code, notes, and snippets.

@motine
Created August 11, 2015 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save motine/d99b7ccee248ff9cdee7 to your computer and use it in GitHub Desktop.
Save motine/d99b7ccee248ff9cdee7 to your computer and use it in GitHub Desktop.
hex_colors=["1f77b4", "ff7f0e", "2ca02c", "d62728", "9467bd", "8c564b", "e377c2", "7f7f7f", "bcbd22", "17becf", "1f77b4", "ff7f0e", "2ca02c"]
values = hex_colors.collect do |hex|
(0..2).collect do |cindex| # collect components (r,g,b)
chex = hex[(cindex*2)..(cindex*2+1)]
c = chex.to_i(16) # convert from hex
mix = c * 0.25 + 255 * 0.75 # mix original color with white (equivalent to 0.25 opacity)
mix.to_i.to_s(16) # convert to hex
end.join()
end
p values
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment