AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Rgb to hex color code generator8/22/2023 ![]() Var seed = input_str.charCodeAt(0) ^ input_str.charCodeAt(1) for seed just take bitwise XOR of first two chars lazy seeded random hack to get values from 0 - 256 TODO: adjust base colour values below based on theme every string with the same first two chars will generate the same pastel colour Inspired by David Crow's answer here: Algorithm to randomly generate an aesthetically-pleasing color palette //magic to convert strings to a nice pastel colour based on first two chars It could be easily extended so that the seed is the XOR of all chars in the string, rather than just the first two. It uses the first two chars of the string as a random seed, then generates R/G/B based on that seed. Here's a solution I came up with to generate aesthetically pleasing pastel colours based on an input string. While this code uses hard-coded colors, you are at least guaranteed to know during development exactly how much contrast you will see between colors in production.Ĭolor list has been lifted from this SO answer, there are other lists with more colors. I suppose you could always add more colors. While this has a limit to only 64 colors, I find most humans can't really tell the difference after that anyway. Will return the same color as the first time Instance.stringToColorHash = instance.veryDifferentColors For every new string, assign the next color in the list: // Takes any string and converts it into a #RRGGBB color. ![]() The easiest way I have found to get around that is to pre-populate a list of very different colors. I find that generating random colors tends to create colors that do not have enough contrast for my taste.
0 Comments
Read More
Leave a Reply. |