Created
October 23, 2022 18:51
-
-
Save matiasfha/e824ed385d1a0f280e4525fac804cc0c to your computer and use it in GitHub Desktop.
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 const stringToPastelColour = function (str: string): string { | |
let hash = 0; | |
for (let i = 0; i < str.length; i++) { | |
hash = str.charCodeAt(i) + ((hash << 6) - hash); | |
hash = hash & hash; // Convert to 32bit integer | |
} | |
const shortened = hash % 360; | |
return 'hsl(' + shortened + ',100%,35%)'; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment