Construct color object from hsv.
@static
@param {Object} cfg
@param {Number} cfg.h Hue
@param {Number} cfg.s Saturation
@param {Number} cfg.v value
@param {Number} cfg.a alpha
559416
function (cfg) {
            var rgb = hsv2rgb(cfg);
            rgb.a = cfg.a;
            return new Color(rgb);
        }
1371906
function StreamConsole(cfg) {
    cfg = cfg || {};
    this.color = cfg.color || true;
    this.timestamp = (typeof cfg.timestamp === 'undefined') ? 'HH:mm:ss ' : cfg.timestamp;
}
1377
def colorHSB(h, s, b):
        
        H, S, B = float(h), float(s/100), float(b/100)
        if S == 0.0:
            return (B, B, B) # achromatic (grey)
        h = H / 60
        i = math.floor(h)
        f = h - i
        v = B
        p = v * (1 - S)
        q = v * (1 - S * f)
        t = v * (1 - S * (1 - f))
        if i == 0:
            return (v, t, b)
        elif i == 1:
            return (q, v, p)
        elif i == 2:
            return (p, v, t)
        elif i == 3:
            return (p, q, v)
        elif i == 4:
            return (t, p, v)
        else: # i == 5 (or i == 6 for the case of H == 360)
            return (v, p, q)
1284827
public static function fromHsl(float $hue, float $saturation, float $lightness): Color
    {
        if (!Validator::isValidHsl($hue, $saturation, $lightness)) {
            throw new InvalidColorException('Invalid HSL value');
        }

        return new self(...array_values(self::hslToRgb($hue, $saturation, $lightness)));
    }
1026112
function fromHSV(h, s, v, a) {
  var color = create();
  setHSV(color, h, s, v, a)
  return color;
}
422720
private static int  hslToRgb(float hue, float sat, float light)
   {
      hue = (hue >= 0f) ? hue % 360f : (hue % 360f) + 360f;  // positive modulo (ie. -10 => 350)
      hue /= 60f;    // [0, 360] -> [0, 6]
      sat /= 100;   // [0, 100] -> [0, 1]
      light /= 100; // [0, 100] -> [0, 1]
      sat = (sat < 0f) ? 0f : (sat > 1f) ? 1f : sat;
      light = (light < 0f) ? 0f : (light > 1f) ? 1f : light;
      float  t1, t2;
      if (light <= 0.5f) {
         t2 = light * (sat + 1f);
      } else {
         t2 = light + sat - (light * sat);
      }
      t1 = light * 2f - t2;
      float  r = hueToRgb(t1, t2, hue + 2f);
      float  g = hueToRgb(t1, t2, hue);
      float  b = hueToRgb(t1, t2, hue - 2f);
      return clamp255(r * 256f)<<16 | clamp255(g * 256f)<<8 | clamp255(b * 256f);
   }
1102440
function (ui, context) {
					if (context != colorMap) {
						switch (settings.color.mode) {
						case 'h':
							var sv = ui.val('sv');
							colorMap.val('xy', {
								x: sv != null ? sv.s : 100,
								y: 100 - (sv != null ? sv.v : 100)
							}, context);
							break;
						case 's':
						case 'a':
							var hv = ui.val('hv');
							colorMap.val('xy', {
								x: hv && hv.h || 0,
								y: 100 - (hv != null ? hv.v : 100)
							}, context);
							break;
						case 'v':
							var hs = ui.val('hs');
							colorMap.val('xy', {
								x: hs && hs.h || 0,
								y: 100 - (hs != null ? hs.s : 100)
							}, context);
							break;
						case 'r':
							var bg = ui.val('bg');
							colorMap.val('xy', {
								x: bg && bg.b || 0,
								y: 255 - (bg && bg.g || 0)
							}, context);
							break;
						case 'g':
							var br = ui.val('br');
							colorMap.val('xy', {
								x: br && br.b || 0,
								y: 255 - (br && br.r || 0)
							}, context);
							break;
						case 'b':
							var rg = ui.val('rg');
							colorMap.val('xy', {
								x: rg && rg.r || 0,
								y: 255 - (rg && rg.g || 0)
							}, context);
							break;
						}
					}
					if (context != colorBar) {
						switch (settings.color.mode) {
						case 'h':
							colorBar.val('y', 360 - (ui.val('h') || 0), context);
							break;
						case 's':
							var s = ui.val('s');
							colorBar.val('y', 100 - (s != null ? s : 100), context);
							break;
						case 'v':
							var v = ui.val('v');
							colorBar.val('y', 100 - (v != null ? v : 100), context);
							break;
						case 'r':
							colorBar.val('y', 255 - (ui.val('r') || 0), context);
							break;
						case 'g':
							colorBar.val('y', 255 - (ui.val('g') || 0), context);
							break;
						case 'b':
							colorBar.val('y', 255 - (ui.val('b') || 0), context);
							break;
						case 'a':
							var a = ui.val('a');
							colorBar.val('y', 255 - (a != null ? a : 255), context);
							break;
						}
					}
				}
1093634
private static int[] hslToRgb(float h, float s, float l) {
        
        int[] ret = new int[3];
        
        float m2 = (l <= 0.5f) ? l * (s + 1) : l + s - l * s; 
        float m1 = l * 2 - m2;
        ret[0] = Math.round(hueToRgb(m1, m2, h + 1.0f/3.0f) * MAX_VALUE);
        ret[1] = Math.round(hueToRgb(m1, m2, h) * MAX_VALUE);
        ret[2] = Math.round(hueToRgb(m1, m2, h - 1.0f/3.0f) * MAX_VALUE);
        return ret;
    }
469964
def rgb_to_hsl_hsv(a, isHSV=True):
    
    R, G, B = a.T

    m = np.min(a, 1).T
    M = np.max(a, 1).T

    C = M - m #chroma
    Cmsk = C != 0

    # Hue
    H = np.zeros(R.shape, int)
    mask = (M == R) & Cmsk
    H[mask] = np.mod(60 * (G[mask] - B[mask]) / C[mask], 360)
    mask = (M == G) & Cmsk
    H[mask] = (60 * (B[mask] - R[mask]) / C[mask] + 120)
    mask = (M == B) & Cmsk
    H[mask] = (60 * (R[mask] - G[mask]) / C[mask] + 240)
    H *= 255
    H /= 360 # if you prefer, leave as 0-360, but don't convert to uint8


    # Saturation
    S = np.zeros(R.shape, int)

    if isHSV:
        # This code is for HSV:
        # Value
        V = M

        # Saturation
        S[Cmsk] = ((255 * C[Cmsk]) / V[Cmsk])
        # H, S, and V are now defined as integers 0-255
        return np.array((H.swapaxes(0, 1), S.swapaxes(0, 1), V.swapaxes(0, 1))).T
    else:
        # This code is for HSL:
        # Value
        L = 0.5 * (M + m)

        # Saturation
        S[Cmsk] = ((C[Cmsk]) / (1 - np.absolute(2 * L[Cmsk]/255.0 - 1)))
        # H, S, and L are now defined as integers 0-255
        return np.array((H.swapaxes(0, 1), S.swapaxes(0, 1), L.swapaxes(0, 1))).T
1082568
function() {
            var hsv = [this.get(this.OPT.HUE), 
                       this.get(this.OPT.SATURATION)/100,
                       this.get(this.OPT.VALUE)/100],
                rgb = Color.hsv2rgb(hsv);

            this.logger.log("HSV converted to RGB " + hsv + " : " + rgb);
            this.set(this.OPT.RGB, rgb);

            this._updateSliders();
        }
701039
def RGB_to_HSL(cobj, *args, **kwargs):
    
    var_R = cobj.rgb_r
    var_G = cobj.rgb_g
    var_B = cobj.rgb_b

    var_max = max(var_R, var_G, var_B)
    var_min = min(var_R, var_G, var_B)

    var_H = __RGB_to_Hue(var_R, var_G, var_B, var_min, var_max)
    var_L = 0.5 * (var_max + var_min)

    if var_max == var_min:
        var_S = 0
    elif var_L <= 0.5:
        var_S = (var_max - var_min) / (2.0 * var_L)
    else:
        var_S = (var_max - var_min) / (2.0 - (2.0 * var_L))

    return HSLColor(
        var_H, var_S, var_L)
168826
public void setColorByHSL(float hue, float saturation, float lightness) {
		float[] arithmeticRGB = ColorUtils.toArithmeticRGB(hue, saturation,
				lightness);
		setRed(arithmeticRGB[0]);
		setGreen(arithmeticRGB[1]);
		setBlue(arithmeticRGB[2]);
	}
674546
function() {
        if (this.hsl !== null) {
            if (this.alpha < 1.0) {
                if (this.perceptual) {
                    return 'rgba(' + hsluv.hsluvToRgb([this.hsl[0], this.hsl[1] * 100, this.hsl[2] * 100]).map(function(c) {
                        return Math.round(c * 255);
                    }).concat(this.round(this.alpha, 2)).join(', ') + ')';
                }
                else {
                    return 'rgba(' + chroma.hsl(this.hsl[0], this.hsl[1], this.hsl[2]).rgb().map(function(c) {
                        return Math.round(c);
                    }).concat(this.round(this.alpha, 2)).join(', ') + ')';
                }
            } else {
                if (this.perceptual) {
                    return hsluv.hsluvToHex([this.hsl[0], this.hsl[1] * 100, this.hsl[2] * 100]);
                }
                else {
                    return chroma.hsl(this.hsl[0], this.hsl[1], this.hsl[2]).hex();
                }
            }
        }
        return '';
    }
35303
function rgbToHsl(rgb) {
		var r, g, b, max, min, d, h, s, l,
			cache,
			del_R, del_G, del_B;

		rgb = ColorHelper.hexToRGB(rgb);
		r = rgb[0] / 255;
		g = rgb[1] / 255;
		b = rgb[2] / 255;
		max = Math.max(r, g, b);
		min = Math.min(r, g, b);

		// Delta RGB value
		d = max - min;
		l = (max + min) / 2;

		// gray?, no chroma...
		if (d === 0) {
			// HSl results from 0 to 1
			h = 0;
			s = 0;
		} else {
			// Chromatic data...
			s = d / (l < 0.5 ? (max + min) : (2 - max - min));

			del_R = (((max - r) / 6) + (d / 2)) / d;
			del_G = (((max - g) / 6) + (d / 2)) / d;
			del_B = (((max - b) / 6) + (d / 2)) / d;

			if (r === max) {
				h = del_B - del_G;
			} else if (g === max) {
				h = (1 / 3) + del_R - del_B;
			} else if (b === max) {
				h = (2 / 3) + del_G - del_R;
			}

			if (h < 0) {
				h += 1;
			}
			if (h > 0) {
				h -= 1;
			}
		}

		h = Math.round(h * 360);
		if (h < 0) {
			h += 360;
		}

		cache = colorCache(this);
		cache.hsl = [h, Math.round(s * 100), Math.round(l * 100)];
		return cache.hsl;
	}
204489
def hsv_2_hex(self, h, s, v):
        
        return self.rgb_2_hex(*hsv_to_rgb(h, s, v))
1168295
def _rgb_to_hsv(rgbs):
    """"""
    rgbs, n_dim = _check_color_dim(rgbs)
    hsvs = list()
    for rgb in rgbs:
        rgb = rgb[:3]  # don't use alpha here
        idx = np.argmax(rgb)
        val = rgb[idx]
        c = val - np.min(rgb)
        if c == 0:
            hue = 0
            sat = 0
        else:
            if idx == 0:  # R == max
                hue = ((rgb[1] - rgb[2]) / c) % 6
            elif idx == 1:  # G == max
                hue = (rgb[2] - rgb[0]) / c + 2
            else:  # B == max
                hue = (rgb[0] - rgb[1]) / c + 4
            hue *= 60
            sat = c / val
        hsv = [hue, sat, val]
        hsvs.append(hsv)
    hsvs = np.array(hsvs, dtype=np.float32)
    if n_dim == 4:
        hsvs = np.concatenate((hsvs, rgbs[:, 3]), axis=1)
    return hsvs
887992
def to_hsv
      red, green, blue = *[r, g, b].collect {|x| x / 255.0}
      max = [red, green, blue].max
      min = [red, green, blue].min

      if min == max
        hue = 0
      elsif max == red
        hue = 60 * ((green - blue) / (max - min))
      elsif max == green
        hue = 60 * ((blue - red) / (max - min)) + 120
      elsif max == blue
        hue = 60 * ((red - green) / (max - min)) + 240
      end

      saturation = (max == 0) ? 0 : (max - min) / max
      [hue % 360, saturation, max]
    end