Skip to content

Instantly share code, notes, and snippets.

@dlanner
Created July 12, 2017 20:04
Show Gist options
  • Select an option

  • Save dlanner/2c0319449e30bae320cc73624146c621 to your computer and use it in GitHub Desktop.

Select an option

Save dlanner/2c0319449e30bae320cc73624146c621 to your computer and use it in GitHub Desktop.
Quick method to arbitrarily convert a text string into an RGB value
def text_to_rgb text
# Get SHA-256 hash of text as hexadecimal
hexdigest = Digest::SHA256.hexdigest(text)
# Convert from hex string to decimal integer
red = hexdigest[0..1].to_i(16)
green = hexdigest[2..3].to_i(16)
blue = hexdigest[4..5].to_i(16)
return [red, green, blue]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment