Created
September 14, 2017 00:30
-
-
Save LynnAU/225b601b356415c5eff6ae0eb46f50a7 to your computer and use it in GitHub Desktop.
Convert an ID string, snowflake or anything, to a decimal colour
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
function IDToColour(id) { | |
var hash = 0; | |
var numbers = id.split(''); | |
for(var i = 0; i < id.length; i++) { | |
hash = id.charCodeAt(i) + ((hash << 5) - hash); | |
} | |
var c = (hash & 0x00FFFFFF).toString(16).toUpperCase(); | |
return parseInt('00000'.substring(0, 6 - c.length) + c, 16); | |
} | |
IDToColour('123456789'); //11669557 | |
IDToColour('987654321'); //1981237 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment