Convert HSB/HSV color to HSL Convert HSB/HSV color to HSL javascript javascript

Convert HSB/HSV color to HSL


I think this is the most precise:

function hsv_to_hsl(h, s, v) {    // both hsv and hsl values are in [0, 1]    var l = (2 - s) * v / 2;    if (l != 0) {        if (l == 1) {            s = 0;        } else if (l < 0.5) {            s = s * v / (l * 2);        } else {            s = s * v / (2 - l * 2);        }    }    return [h, s, l];}


Short but precise

Try this (s,v,l in [0,1], more: hsv2rgb rgb2hsv and hsl2rgb rgb2hsl)

let hsl2hsv = (h,s,l,v=s*Math.min(l,1-l)+l) => [h, v?2-2*l/v:0, v];let hsv2hsl = (h,s,v,l=v-v*s/2, m=Math.min(l,1-l)) => [h,m?(v-l)/m:0,l];