Created
December 10, 2017 13:57
-
-
Save tsouk/80de7e3698bbe45a2a150430b7a4d24d to your computer and use it in GitHub Desktop.
html2graph colors in console
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 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