Created
July 12, 2017 20:04
-
-
Save dlanner/2c0319449e30bae320cc73624146c621 to your computer and use it in GitHub Desktop.
Quick method to arbitrarily convert a text string into an RGB value
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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