Closed stereobooster closed 6 years ago
Or other solution found here http://makandracards.com/makandra/24449-hash-any-ruby-object-into-an-rgb-color
def colorize(object)
# Inspired by Jeremy Ruten (http://stackoverflow.com/questions/1698318/ruby-generate-a-random-hex-color)
hash = object.hash # hash an object, returns a Fixnum
trimmed_hash = hash & 0xffffff # trim the hash to the size of 6 hex digits (& is bit-wise AND)
hex_code = "%06x" % trimmed_hash # format as at least 6 hex digits, pad with zeros
"##{hex_code}"
end
Interesting idea. I’ll have to see how I want to do this. As I understand this, this would be the colour equivalent of an identicon?
Yes. I want to generate avatars like mobile gmail does. Initials plus color.
Basically port https://github.com/zenozeng/color-hash from JS to ruby