Mapping arbitrary strings to RGB values

前端 未结 8 1335
迷失自我
迷失自我 2021-01-05 03:49

I have a huge set of arbitrary natural language strings. For my tool to analyze them I need to convert each string to unique color value (RGB or other). I need color contras

8条回答
  •  既然无缘
    2021-01-05 04:06

    It sounds like you want a hash of some sort. It doesn't need to be secure (so nothing as complicated as MD5 or SHA) but something along the lines of:

    char1 + char2 + char3 + ... + charN % MAX_COLOUR_VALUE
    

    would work as a simple first step. You could also do fancier things along the lines of having each character act as an 'amplitude' for R,G and B (e could be +1R, +2G and -4B, etc.) and then simply add up all the values in a string... clamp them at the end and you have a method of turning arbitrary length strings into colours as a 'colour hash' sort of process.

提交回复
热议问题