Skip to content

Instantly share code, notes, and snippets.

@matiasfha
Created October 23, 2022 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matiasfha/e824ed385d1a0f280e4525fac804cc0c to your computer and use it in GitHub Desktop.
Save matiasfha/e824ed385d1a0f280e4525fac804cc0c to your computer and use it in GitHub Desktop.
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