Skip to content

Instantly share code, notes, and snippets.

@hightemp
Created August 31, 2020 07:14
Show Gist options
  • Save hightemp/7bdd690473a910e3be18b04f8e29258b to your computer and use it in GitHub Desktop.
Save hightemp/7bdd690473a910e3be18b04f8e29258b to your computer and use it in GitHub Desktop.
color hash javascript
export function fnGenerateColor(sText, bDarkMode=false) {
var iL = sText.length;
var iSum = 0;
for (var iI=0; iI<iL; iI++) {
iSum += iI*iI*sText.charCodeAt(iI);
}
var iH = iSum % 365;
var iS = 100;
var iL = iSum % 50;
var iLL = iL + 20;
var iLD = iL + 50;
return bDarkMode ? `hsl(${iH}, ${iS}%, ${iLD}%)` : `hsl(${iH}, ${iS}%, ${iLL}%)`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment