Created
May 24, 2013 04:53
-
-
Save pifantastic/5641337 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
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