Last active
October 21, 2017 12:57
-
-
Save sergiop/6afafa3e5e54ef30527488ea44f94604 to your computer and use it in GitHub Desktop.
Use this simple function to compute a HSL color for a given string.
This file contains 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
function stringToHslColor(str, s, l) { | |
var hash = 0; | |
for (var i = 0; i < str.length; i++) { | |
hash = str.charCodeAt(i) + ((hash << 5) - hash); | |
} | |
var h = hash % 360; | |
return 'hsl('+h+', '+s+'%, '+l+'%)'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment