Skip to content

Instantly share code, notes, and snippets.

@tsouk
Created December 10, 2017 13:57
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 tsouk/80de7e3698bbe45a2a150430b7a4d24d to your computer and use it in GitHub Desktop.
Save tsouk/80de7e3698bbe45a2a150430b7a4d24d to your computer and use it in GitHub Desktop.
html2graph colors in console
function hashCode(str) {
var hash = 0;
for (var i = 0; i < str.length; i++) {
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
return hash;
}
function intToRGB(i) {
var c = (i & 0x00FFFFFF)
.toString(16)
.toUpperCase();
return "00000".substring(0, 6 - c.length) + c;
}
function name2color (name) {
color = intToRGB(hashCode(name));
console.log('%c ', 'background: #' + color);
}
htmlNodes = ['html', 'li', 'ul', 'div', 'a', 'img', 'meta', 'link', 'script'];
for (i=0; i<htmlNodes.length ; i++) { name2color(htmlNodes[i] + '3000') }
//5555000000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment