Skip to content

Instantly share code, notes, and snippets.

@koolamusic
Last active February 28, 2021 10:06
Show Gist options
  • Save koolamusic/ebe5aac6a8fa1c172a0a6dcd8ac9618f to your computer and use it in GitHub Desktop.
Save koolamusic/ebe5aac6a8fa1c172a0a6dcd8ac9618f to your computer and use it in GitHub Desktop.
Convert a String to HSL Color
// Based on HSL. Generate an Abritrary pastel tone color based on input text.
/*
1. s = saturation
2. l = lightness
*/
function stringToHslColor(str, s=30, l=80) {
const hash = 0;
for (let i = 0; i < str.length; i++) {
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
const 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