Skip to content

Instantly share code, notes, and snippets.

@sudodoki
Created September 21, 2013 14:33
Show Gist options
  • Select an option

  • Save sudodoki/6651214 to your computer and use it in GitHub Desktop.

Select an option

Save sudodoki/6651214 to your computer and use it in GitHub Desktop.
function to convert hsl values into rgb
/**
* function to convert hue, saturation, lightness in browser
* @param {integer} h in range of 0..360
* @param {saturation} s in range of 0..100 (percents)
* @param {lightness} l in range of 0..100 (percents)
* @return {array} array [r, g, b] of integers (0..255) representing each part
*/
hsl2rgb = function (h, s, l) {
var transmitter = document.createElement("div");
hsl2rgb = function () {
transmitter.style.backgroundColor = "hsl(" + h + ", " + s + "%, " + l + "%)";
return transmitter.style.backgroundColor
.slice(4, - 1)
.split(', ')
.map(function(x){return parseInt(x)});
}
return hsl2rgb(h,s,l);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment