Last active
August 29, 2015 14:08
-
-
Save kadimi/a0549c230a3d9f0f1903 to your computer and use it in GitHub Desktop.
HSL difference between two colors
This file contains 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
/** | |
* 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