flight mode to color conversion
169454
def _kml_default_colors(x):
    
    x = max([x, 0])
    colors_arr = [simplekml.Color.red, simplekml.Color.green, simplekml.Color.blue,
                  simplekml.Color.violet, simplekml.Color.yellow, simplekml.Color.orange,
                  simplekml.Color.burlywood, simplekml.Color.azure, simplekml.Color.lightblue,
                  simplekml.Color.lawngreen, simplekml.Color.indianred, simplekml.Color.hotpink]
    return colors_arr[x]
958538
function (colorMode) {
					var active = color.active, // local copies for YUI compressor
						clientPath = images.clientPath,
						hex = active.val('hex'),
						rgbMap,
						rgbBar;
					settings.color.mode = colorMode;
					switch (colorMode) {
					case 'h':
						setTimeout(function () {
							setBG.call($this, colorMapDiv, 'transparent');
							setImgLoc.call($this, colorMapL1, 0);
							setAlpha.call($this, colorMapL1, 100);
							setImgLoc.call($this, colorMapL2, 260);
							setAlpha.call($this, colorMapL2, 100);
							setBG.call($this, colorBarDiv, 'transparent');
							setImgLoc.call($this, colorBarL1, 0);
							setAlpha.call($this, colorBarL1, 100);
							setImgLoc.call($this, colorBarL2, 260);
							setAlpha.call($this, colorBarL2, 100);
							setImgLoc.call($this, colorBarL3, 260);
							setAlpha.call($this, colorBarL3, 100);
							setImgLoc.call($this, colorBarL4, 260);
							setAlpha.call($this, colorBarL4, 100);
							setImgLoc.call($this, colorBarL6, 260);
							setAlpha.call($this, colorBarL6, 100);
						}, 0);
						colorMap.range('all', {
							minX: 0,
							maxX: 100,
							minY: 0,
							maxY: 100
						});
						colorBar.range('rangeY', {
							minY: 0,
							maxY: 360
						});
						if (active.val('ahex') == null) break;
						colorMap.val('xy', {
							x: active.val('s'),
							y: 100 - active.val('v')
						}, colorMap);
						colorBar.val('y', 360 - active.val('h'), colorBar);
						break;
					case 's':
						setTimeout(function () {
							setBG.call($this, colorMapDiv, 'transparent');
							setImgLoc.call($this, colorMapL1, -260);
							setImgLoc.call($this, colorMapL2, -520);
							setImgLoc.call($this, colorBarL1, -260);
							setImgLoc.call($this, colorBarL2, -520);
							setImgLoc.call($this, colorBarL6, 260);
							setAlpha.call($this, colorBarL6, 100);
						}, 0);
						colorMap.range('all', {
							minX: 0,
							maxX: 360,
							minY: 0,
							maxY: 100
						});
						colorBar.range('rangeY', {
							minY: 0,
							maxY: 100
						});
						if (active.val('ahex') == null) break;
						colorMap.val('xy', {
							x: active.val('h'),
							y: 100 - active.val('v')
						}, colorMap);
						colorBar.val('y', 100 - active.val('s'), colorBar);
						break;
					case 'v':
						setTimeout(function () {
							setBG.call($this, colorMapDiv, '000000');
							setImgLoc.call($this, colorMapL1, -780);
							setImgLoc.call($this, colorMapL2, 260);
							setBG.call($this, colorBarDiv, hex);
							setImgLoc.call($this, colorBarL1, -520);
							setImgLoc.call($this, colorBarL2, 260);
							setAlpha.call($this, colorBarL2, 100);
							setImgLoc.call($this, colorBarL6, 260);
							setAlpha.call($this, colorBarL6, 100);
						}, 0);
						colorMap.range('all', {
							minX: 0,
							maxX: 360,
							minY: 0,
							maxY: 100
						});
						colorBar.range('rangeY', {
							minY: 0,
							maxY: 100
						});
						if (active.val('ahex') == null) break;
						colorMap.val('xy', {
							x: active.val('h'),
							y: 100 - active.val('s')
						}, colorMap);
						colorBar.val('y', 100 - active.val('v'), colorBar);
						break;
					case 'r':
						rgbMap = -1040;
						rgbBar = -780;
						colorMap.range('all', {
							minX: 0,
							maxX: 255,
							minY: 0,
							maxY: 255
						});
						colorBar.range('rangeY', {
							minY: 0,
							maxY: 255
						});
						if (active.val('ahex') == null) break;
						colorMap.val('xy', {
							x: active.val('b'),
							y: 255 - active.val('g')
						}, colorMap);
						colorBar.val('y', 255 - active.val('r'), colorBar);
						break;
					case 'g':
						rgbMap = -1560;
						rgbBar = -1820;
						colorMap.range('all', {
							minX: 0,
							maxX: 255,
							minY: 0,
							maxY: 255
						});
						colorBar.range('rangeY', {
							minY: 0,
							maxY: 255
						});
						if (active.val('ahex') == null) break;
						colorMap.val('xy', {
							x: active.val('b'),
							y: 255 - active.val('r')
						}, colorMap);
						colorBar.val('y', 255 - active.val('g'), colorBar);
						break;
					case 'b':
						rgbMap = -2080;
						rgbBar = -2860;
						colorMap.range('all', {
							minX: 0,
							maxX: 255,
							minY: 0,
							maxY: 255
						});
						colorBar.range('rangeY', {
							minY: 0,
							maxY: 255
						});
						if (active.val('ahex') == null) break;
						colorMap.val('xy', {
							x: active.val('r'),
							y: 255 - active.val('g')
						}, colorMap);
						colorBar.val('y', 255 - active.val('b'), colorBar);
						break;
					case 'a':
						setTimeout(function () {
							setBG.call($this, colorMapDiv, 'transparent');
							setImgLoc.call($this, colorMapL1, -260);
							setImgLoc.call($this, colorMapL2, -520);
							setImgLoc.call($this, colorBarL1, 260);
							setImgLoc.call($this, colorBarL2, 260);
							setAlpha.call($this, colorBarL2, 100);
							setImgLoc.call($this, colorBarL6, 0);
							setAlpha.call($this, colorBarL6, 100);
						}, 0);
						colorMap.range('all', {
							minX: 0,
							maxX: 360,
							minY: 0,
							maxY: 100
						});
						colorBar.range('rangeY', {
							minY: 0,
							maxY: 255
						});
						if (active.val('ahex') == null) break;
						colorMap.val('xy', {
							x: active.val('h'),
							y: 100 - active.val('v')
						}, colorMap);
						colorBar.val('y', 255 - active.val('a'), colorBar);
						break;
					default:
						throw ('Invalid Mode');
						break;
					}
					switch (colorMode) {
					case 'h':
						break;
					case 's':
					case 'v':
					case 'a':
						setTimeout(function () {
							setAlpha.call($this, colorMapL1, 100);
							setAlpha.call($this, colorBarL1, 100);
							setImgLoc.call($this, colorBarL3, 260);
							setAlpha.call($this, colorBarL3, 100);
							setImgLoc.call($this, colorBarL4, 260);
							setAlpha.call($this, colorBarL4, 100);
						}, 0);
						break;
					case 'r':
					case 'g':
					case 'b':
						setTimeout(function () {
							setBG.call($this, colorMapDiv, 'transparent');
							setBG.call($this, colorBarDiv, 'transparent');
							setAlpha.call($this, colorBarL1, 100);
							setAlpha.call($this, colorMapL1, 100);
							setImgLoc.call($this, colorMapL1, rgbMap);
							setImgLoc.call($this, colorMapL2, rgbMap - 260);
							setImgLoc.call($this, colorBarL1, rgbBar - 780);
							setImgLoc.call($this, colorBarL2, rgbBar - 520);
							setImgLoc.call($this, colorBarL3, rgbBar);
							setImgLoc.call($this, colorBarL4, rgbBar - 260);
							setImgLoc.call($this, colorBarL6, 260);
							setAlpha.call($this, colorBarL6, 100);
						}, 0);
						break;
					}
					if (active.val('ahex') == null) return;
					activeColorChanged.call($this, active);
				}
1116031
function convertColorToRGBA(color) {
  const cstr = `${color}`.toLowerCase().trim() || '';

  if (!/^rgba?\(.+?\)$/.test(cstr)) {
    // Convert both color names and hex colors to rgba
    const hexColor = convertColorNameToHex(color);
    return convertHexColorToRgba(hexColor);
  }

  // Convert rgb to rgba
  const channels = cstr.match(/([\-0-9.]+)/g) || [];

  switch (channels.length) {
    case 3:
      // Convert rgb to rgba
      return `rgba(${channels.join(', ')}, 1)`;

    case 4:
      // Format rgba
      return `rgba(${channels.join(', ')})`;

    default:
      // Unexpected color format. Leave it untouched (let the user handle it)
      return color;
  }
}
222411
def chromaticity_to_XYZ(white, red, green, blue):
    """"""
    xW, yW = white
    xR, yR = red
    xG, yG = green
    xB, yB = blue
    R = G = B = 1.0

    z = yW * ((xG - xB) * yR - (xR - xB) * yG + (xR - xG) * yB)
    YA = yR / R  * ((xG - xB) * yW - (xW - xB) * yG + (xW - xG) * yB) / z
    XA = YA * xR / yR
    ZA = YA * ((1 - xR) / yR - 1)
    YB = - yG / G * ((xR - xB) * yW - (xW - xB) * yR + (xW - xR) * yB) / z
    XB = YB * xG / yG
    ZB = YB * ((1 - xG) / yG - 1)
    YC = yB / B * ((xR - xG) * yW - (xW - xG) * yR + (xW - xR) * yG) / z
    XC = YC * xB / yB
    ZC = YC * ((1 - xB) / yB - 1)
    XW = XA * R + XB * G + XC * B
    YW = YA * R + YB * G + YC * B
    ZW = ZA * R + ZB * G + ZC * B

    return (XW, YW, ZW), (XA, YA, ZA), (XB, YB, ZB), (XC, YC, ZC)
1327805
def update_color_state(self, light):
        """"""
        x, y = light.xy or (None, None)
        self.async_update({
            'state': {
                'bri': light.brightness,
                'hue': light.hue,
                'sat': light.sat,
                'ct': light.ct,
                'x': x,
                'y': y,
                'colormode': light.colormode,
            },
        })
658049
def colorlog(msg, color, bold=False, blink=False):
    """"""

    # ANSI Escape Codes
    PINK_COL = '\x1b[35m'
    GREEN_COL = '\x1b[32m'
    RED_COL = '\x1b[31m'
    YELLOW_COL = '\x1b[33m'
    BLINK = '\x1b[5m'
    RESET = '\x1b[0m'

    if platform.system() != 'Windows':
        if blink:
            msg = BLINK + msg + RESET
        if color == 'yellow':
            msg = YELLOW_COL + msg + RESET
        if color == 'red':
            msg = RED_COL + msg + RESET
        if color == 'green':
            msg = GREEN_COL + msg + RESET
        if color == 'pink':
            msg = PINK_COL + msg + RESET
    return msg
1249009
def colorscale(mag, cmin, cmax):
    
    # Normalize to 0-1
    try:
        x = float(mag-cmin)/(cmax-cmin)
    except ZeroDivisionError:
        x = 0.5  # cmax == cmin
    blue = min((max((4*(0.75-x), 0.)), 1.))
    red = min((max((4*(x-0.25), 0.)), 1.))
    green = min((max((4*abs(x-0.5)-1., 0.)), 1.))
    return red, green, blue
814178
def _gen_packet_setcolor(self, sequence, hue, sat, bri, kel, fade):
        
        hue = min(max(hue, HUE_MIN), HUE_MAX)
        sat = min(max(sat, SATURATION_MIN), SATURATION_MAX)
        bri = min(max(bri, BRIGHTNESS_MIN), BRIGHTNESS_MAX)
        kel = min(max(kel, TEMP_MIN), TEMP_MAX)

        reserved1 = pack("<B", 0)
        hue = pack("<H", hue)
        saturation = pack("<H", sat)
        brightness = pack("<H", bri)
        kelvin = pack("<H", kel)
        duration = pack("<I", fade)

        # assemble payload
        payload = bytearray(reserved1)
        payload.extend(hue)
        payload.extend(saturation)
        payload.extend(brightness)
        payload.extend(kelvin)
        payload.extend(duration)

        return self._gen_packet(sequence, PayloadType.SETCOLOR, payload)
1019929
def get_bgcolor(self, index):
        """"""
        if index.column() == 0:
            color = QColor(Qt.lightGray)
            color.setAlphaF(.05)
        elif index.column() < 3:
            color = QColor(Qt.lightGray)
            color.setAlphaF(.2)
        else:
            color = QColor(Qt.lightGray)
            color.setAlphaF(.3)
        return color
682294
def mode(self):
        """"""
        m = ''
        if self.indexed:
            m = 'P'
        elif self.bits_per_component == 1:
            m = '1'
        elif self.bits_per_component == 8:
            if self.colorspace == '/DeviceRGB':
                m = 'RGB'
            elif self.colorspace == '/DeviceGray':
                m = 'L'
            elif self.colorspace == '/DeviceCMYK':
                m = 'CMYK'
        if m == '':
            raise NotImplementedError("Not sure how to handle PDF image of this type")
        return m
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();
        }
548081
def RgbToRyb(hue):
    '''

    '''
    d = hue % 15
    i = int(hue / 15)
    x0 = _RybWheel[i]
    x1 = _RybWheel[i+1]
    return x0 + (x1-x0) * d / 15
205387
function useColors() {
	return 'colors' in exports.inspectOpts ?
		Boolean(exports.inspectOpts.colors) :
		tty.isatty(process.stderr.fd);
}
958509
def MWColorMapping(maptype='jet', reverse=True):
     
    d = {'A':89,'R':174,'N':132,'D':133,'C':121,'Q':146,'E':147,\
         'G':75,'H':155,'I':131,'L':131,'K':146,'M':149,'F':165,\
         'P':115,'S':105,'T':119,'W':204,'Y':181,'V':117}
    
    aas = sorted(AA_TO_INDEX.keys())
    mws  = [d[aa] for aa in aas]
    if reverse:
        mws = [-1 * x for x in mws]
    mapper = pylab.cm.ScalarMappable(cmap=maptype)
    mapper.set_clim(min(mws), max(mws))
    mapping_d = {'*':'#000000'}
    for (aa, h) in zip(aas, mws):
        tup = mapper.to_rgba(h, bytes=True)
        (red, green, blue, alpha) = tup
        mapping_d[aa] = '#%02x%02x%02x' % (red, green, blue)
        assert len(mapping_d[aa]) == 7
    cmap = mapper.get_cmap()
    return (cmap, mapping_d, mapper)
342481
def _string_to_rgb(color):
    """"""
    if not color.startswith('#'):
        if color.lower() not in _color_dict:
            raise ValueError('Color "%s" unknown' % color)
        color = _color_dict[color]
        assert color[0] == '#'
    # hex color
    color = color[1:]
    lc = len(color)
    if lc in (3, 4):
        color = ''.join(c + c for c in color)
        lc = len(color)
    if lc not in (6, 8):
        raise ValueError('Hex color must have exactly six or eight '
                         'elements following the # sign')
    color = np.array([int(color[i:i+2], 16) / 255. for i in range(0, lc, 2)])
    return color
1033731
def set_rgb(self, red, green, blue):
        
        x, y = rgb_to_xy(red, green, blue)
        self.xy = [x, y]
1178093
def _glsl_mix(controls=None):
    """"""
    assert (controls[0], controls[-1]) == (0., 1.)
    ncolors = len(controls)
    assert ncolors >= 2
    if ncolors == 2:
        s = "    return mix($color_0, $color_1, t);\n"
    else:
        s = ""
        for i in range(ncolors-1):
            if i == 0:
                ifs = 'if (t < %.6f)' % (controls[i+1])
            elif i == (ncolors-2):
                ifs = 'else'
            else:
                ifs = 'else if (t < %.6f)' % (controls[i+1])
            adj_t = '(t - %s) / %s' % (controls[i],
                                       controls[i+1] - controls[i])
            s += ("%s {\n    return mix($color_%d, $color_%d, %s);\n} " %
                  (ifs, i, i+1, adj_t))
    return "vec4 colormap(float t) {\n%s\n}" % s