Last active
June 11, 2019 07:30
-
-
Save azinkey/ba21d8e3a17346e44c1470e4388e6f68 to your computer and use it in GitHub Desktop.
integer number(id) to color code (12345 => #ffffff)
This file contains 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 idToColor(id){ | |
var clrs = []; | |
clrs[0] = ['1','3','5','7','9','A','B','C','D','E']; | |
clrs[1] = ['2','4','6','8','0','F','1','3','5','7']; | |
var min=0, max=1; | |
var minC=0, maxC=9; | |
var randomC = Math.floor(Math.random() * (+maxC - +minC)) + +minC; | |
var $id = (id.length < 6) ? id.padEnd(6, randomC ) : id.slice(-6); | |
var $chars = $id.split(''); | |
var $color = '#'; | |
for($c in $chars){ | |
var rand =Math.floor(Math.random() * (+max - +min)) + +min; | |
$color += clrs[rand][$chars[$c]]; | |
} | |
return $color; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment