Created
August 31, 2020 07:14
-
-
Save hightemp/7bdd690473a910e3be18b04f8e29258b to your computer and use it in GitHub Desktop.
color hash javascript
This file contains hidden or 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
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