Skip to content

Instantly share code, notes, and snippets.

@sergiop
Last active October 21, 2017 12:57
Show Gist options
  • Save sergiop/6afafa3e5e54ef30527488ea44f94604 to your computer and use it in GitHub Desktop.
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.
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