It looks like your colour picker is expressed in the HSV (Hue/Saturation/Value) coordinates.
Wikipedia has a decent article on this and you can work out the conversion formula from the information given there.
Alternatively a quick search on Google returns, e.g., this page with a formula that you can use to convert HSV to HSL: http://codeitdown.com/hsl-hsb-hsv-color/. Assuming that your x
and y
both run from 0 to 100, the calculation should read:
hsv_value = 1 - (y / 100);
hsv_saturation = x / 100;
lightness = (hsv_value / 2) * (2 - hsv_saturation);
saturation = (hsv_value * hsv_saturation) / (1 - Math.abs(2 * lightness - 1));
This returns saturation
and lightness
in the range [0,1]. Also, why are you clamp
ing your x
and y
coordinates?