Module: Colorizer
Overview
Instance Method Summary collapse
Instance Method Details
#colorize(object) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/colorizer.rb', line 5 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 |
#colorize_similarly(object, saturation, lightness) ⇒ Object
13 14 15 16 |
# File 'lib/colorizer.rb', line 13 def colorize_similarly(object, saturation, lightness) rnd = ((XXhash.xxh64(object) * 7) % 100) * 0.01 hsl_to_rgb(rnd, saturation, lightness) end |