Given a colorpicker that looks like so:
I am trying to calculate the HSL values given the x and y position of the cursor plus the hue from the slider on the right. My math skills are pretty weak, and although what I have is close, trying to grab a really light full-strength colour is troublesome, (it ends up being too gray). This is the current function I'm using:
getHSL = function(h, x, y) {
var hsl, hue, lightness, saturation;
hue = parseInt(h, 10);
if (hue === 360) {
hue = 0;
}
saturation = x;
lightness = (50 * (1 - (x / 100)) + 50) * (1 - (y / 100));
hue = Math.round(clamp(hue, 0, 360));
saturation = Math.round(clamp(saturation, 0, 100));
lightness = Math.round(clamp(lightness, 0, 100));
hsl = {
hue: hue,
saturation: saturation,
lightness: lightness
};
return hsl;
};
Is this the wrong way to do it? The results are actually very close to correct, but a tad off with really light full-strength colors.