Skip to content

Instantly share code, notes, and snippets.

View sergiop's full-sized avatar

Sergio Pedercini sergiop

View GitHub Profile
@sergiop
sergiop / stringToHslColor.js
Last active October 21, 2017 12:57
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+'%)';
}