Skip to content

Instantly share code, notes, and snippets.

@cvn
Created February 25, 2014 03:11
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 cvn/9201922 to your computer and use it in GitHub Desktop.
Save cvn/9201922 to your computer and use it in GitHub Desktop.
function colorFromString(str, length) {
if (!str){
str = 'null';
}
if (length){
jobColorSource = hex_md5(str.substring(0,length));
}else{
jobColorSource = hex_md5(str.substring(0,4));
}
jobColor = new Array(jobColorSource.substr(0,2), jobColorSource.substr(2,2), jobColorSource.substr(4,2));
for(i=0;i<jobColor.length;i++){
jobColor[i] = Number(Math.min(Math.floor(parseInt(jobColor[i],16)/2)+128),220).toString(16);
}
return jobColor.join('');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment