I'd like to colorify user names in a MediaWiki page based on hashes of the string containing the username itself. The only thing I'd like to know is how to get from a letter string a number from 0 to 360 so that I can specify the hue using hsl function in CSS.
Asked
Active
Viewed 144 times
1 Answers
0
a simple javascript way could be:
str="A String"
value = 0
for (var i = 0, len = str.length; i < len; i++) {
value += str.charCodeAt(i);
}
next you have to reduce/convert the value to your colorvalue
i assume a max string of 16chars --> Z*16 toASCII = 1440. Thats your max ASCII Value. You can reduce your usernames to this value.
Example
"John Due".asciiValue == 717 --> reduced to 360-System (your colorsystem) --> colorVal=(360*717)/1440 = 179,25 --> mod --> 179

Matthias Hamann
- 719
- 8
- 27