Created
January 13, 2015 17:05
-
-
Save rummik/dfb55e42e33c488fab74 to your computer and use it in GitHub Desktop.
// source https://jsbin.com/saboga
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<div class="nick">rummik</div> | |
<div class="nick">IotaSamurai</div> | |
<div class="nick">foo</div> | |
<div class="nick">blsaadfah</div> | |
<script id="jsbin-javascript"> | |
/** | |
* Create a HSL color based on nick input. | |
* @param {string} nick Nick to color | |
* @return {string} HSL value of computed nick color | |
*/ | |
function colorizeNick(nick) { | |
var hue = 0; | |
for (var i=1,l=nick.length; i<l; i++) { | |
hue += nick.charCodeAt(i); | |
} | |
hue %= 360; | |
return 'hsl(' + hue + ', 80%, 60%)'; | |
} | |
[].slice.apply(document.querySelectorAll('.nick')) | |
.forEach(function(element) { | |
element.style.color = colorizeNick(element.innerHTML); | |
}); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">/** | |
* Create a HSL color based on nick input. | |
* @param {string} nick Nick to color | |
* @return {string} HSL value of computed nick color | |
*/ | |
function colorizeNick(nick) { | |
var hue = 0; | |
for (var i=1,l=nick.length; i<l; i++) { | |
hue += nick.charCodeAt(i); | |
} | |
hue %= 360; | |
return 'hsl(' + hue + ', 80%, 60%)'; | |
} | |
[].slice.apply(document.querySelectorAll('.nick')) | |
.forEach(function(element) { | |
element.style.color = colorizeNick(element.innerHTML); | |
});</script></body> | |
</html> |
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
/** | |
* Create a HSL color based on nick input. | |
* @param {string} nick Nick to color | |
* @return {string} HSL value of computed nick color | |
*/ | |
function colorizeNick(nick) { | |
var hue = 0; | |
for (var i=1,l=nick.length; i<l; i++) { | |
hue += nick.charCodeAt(i); | |
} | |
hue %= 360; | |
return 'hsl(' + hue + ', 80%, 60%)'; | |
} | |
[].slice.apply(document.querySelectorAll('.nick')) | |
.forEach(function(element) { | |
element.style.color = colorizeNick(element.innerHTML); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment