I had to write some code today to convert words into colors, which was a lot of fun. I liked it so such I had to put a working example online.
The code is a simple function. How it works:
- We have three channels: red, green, and blue.
- Iterate over the word, with the first character adding to red, the second to green, and the third to blue. This continues for the whole word.
- Add the Unicode value of the character to a sum. Each time you add a new letter, multiply the value by a multiplier. This multiplier starts at 11 and is multiplied by 11 every time you go through three letters.
- Mod each sum by 256 to get the channel value.