Skip to content

Instantly share code, notes, and snippets.

@gderosa
Last active December 17, 2015 07:59
Show Gist options
  • Save gderosa/5577274 to your computer and use it in GitHub Desktop.
Save gderosa/5577274 to your computer and use it in GitHub Desktop.
require 'digest/sha1'
0.upto(1000).each do |i|
s = i.to_s
digest = Digest::SHA1.hexdigest(s)
fg = digest[0..5]
fg_ = {}
fg_[:r] = fg[0..1]
fg_[:g] = fg[2..3]
fg_[:b] = fg[4..5]
bg_ = {}
bg = ''
# maximize contrast
delta = 0x80
[:r, :g, :b].each do |component|
level = fg_[component].to_i(16)
bg_level = level + delta
bg_[component] = '%02x' % (bg_level % 0x100)
bg << bg_[component]
end
print %Q{<span style="display:inline-block; width:5ex; font-weight: bold; color:##{fg}; background:##{bg}; text-align:right;padding-right:0.2ex;">#{s}</span>}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment