Skip to content

Instantly share code, notes, and snippets.

@pifantastic
Created May 24, 2013 04:53
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 pifantastic/5641337 to your computer and use it in GitHub Desktop.
Save pifantastic/5641337 to your computer and use it in GitHub Desktop.
var colorHash = function (str) {
// djb2 hash: http://www.cse.yorku.ca/~oz/hash.html
var hash = 5381;
for (i = 0; i < str.length; i++) {
hash = ((hash << 5) + hash) + str.charCodeAt(i);
}
// Help from: http://www.paulirish.com/2009/random-hex-color-code-snippets/
var color = Math.round(11184810 * Math.abs(hash) / Math.pow(2, 32));
return '#' + ('00000' + color.toString(16)).slice(-6);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment