Skip to content

Instantly share code, notes, and snippets.

@kadimi
Last active August 29, 2015 14:08
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 kadimi/a0549c230a3d9f0f1903 to your computer and use it in GitHub Desktop.
Save kadimi/a0549c230a3d9f0f1903 to your computer and use it in GitHub Desktop.
HSL difference between two colors
/**
* Calculate the difference in hue, saturation and lightness between two colors
*
* The function requires tinycolor (https://github.com/bgrins/TinyColor)
* Example: http://jsfiddle.net/nabil_kadimi/a9cqqth0/2/
*
* @param {String} s Source color in hexadecimal
* @param {String} d Destination color in hexadecimal
* @return {Array} Array of differences [hue, saturtion, lightness]
*/
function hslDiff(s, d) {
s = tinycolor(s);
d = tinycolor(d);
var diff = [];
for (i in ['h','s','l']){
diff['hsl'[i]] = d.toHsl()['hsl'[i]] - s.toHsl()['hsl'[i]];
}
return diff;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment