Skip to content

Instantly share code, notes, and snippets.

@rummik
Created January 13, 2015 17:05
Show Gist options
  • Save rummik/dfb55e42e33c488fab74 to your computer and use it in GitHub Desktop.
Save rummik/dfb55e42e33c488fab74 to your computer and use it in GitHub Desktop.
<!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>
/**
* 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