Interpolates the color gradients between a list of hex colors.
779455
def polylinear_gradient(colors, n):
    
    n_out = int(float(n) / (len(colors)-1))
    gradient = linear_gradient(colors[0], colors[1], n_out)

    if len(colors) == len(gradient):
        return gradient

    for col in range(1, len(colors) - 1):
        next_colors = linear_gradient(colors[col], colors[col+1], n_out+1)
        gradient += next_colors[1:] if len(next_colors) > 1 else next_colors
    return gradient
267982
def generateCustomColorRamp(cls, colors=[], interpolatedPoints=10):
        
        if not (isinstance(colors, list)):
            print('COLOR RAMP GENERATOR WARNING: colors must be passed in as a list of RGB tuples.')
            raise

        numColors = len(colors)

        colorRamp = []

        # Iterate over colors
        for index in range (0, numColors - 1):
            bottomColor = colors[index]
            topColor = colors[index + 1]

            colorRamp.append(bottomColor)

            # Calculate slopes
            rSlope = (topColor[0] - bottomColor[0]) / float(interpolatedPoints)
            gSlope = (topColor[1] - bottomColor[1]) / float(interpolatedPoints)
            bSlope = (topColor[2] - bottomColor[2]) / float(interpolatedPoints)

            # Interpolate colors
            for point in range(1, interpolatedPoints):
                red = int(rSlope * point + bottomColor[0])
                green = int(gSlope * point + bottomColor[1])
                blue = int(bSlope * point + bottomColor[2])
                color = (red, green, blue)

                # Make sure the color ramp contains unique colors
                if not (color in colorRamp):
                    colorRamp.append(color)

        # Append the last color
        colorRamp.append(colors[-1])

        return colorRamp
66080
def get_color_between(color1, color2, i):
    
    if i <= 0:
        return color1
    if i >= 1:
        return color2
    return (int(color1[0] + (color2[0] - color1[0]) * i),
            int(color1[1] + (color2[1] - color1[1]) * i),
            int(color1[2] + (color2[2] - color1[2]) * i))
659552
def _build_color_table():
        
        FG = FOREGROUND_COLOR
        BG = BACKROUND_COLOR

        return [
            (0x00, 0x00, 0x00, FG.BLACK, BG.BLACK),
            (0x00, 0x00, 0xaa, FG.BLUE, BG.BLUE),
            (0x00, 0xaa, 0x00, FG.GREEN, BG.GREEN),
            (0x00, 0xaa, 0xaa, FG.CYAN, BG.CYAN),
            (0xaa, 0x00, 0x00, FG.RED, BG.RED),
            (0xaa, 0x00, 0xaa, FG.MAGENTA, BG.MAGENTA),
            (0xaa, 0xaa, 0x00, FG.YELLOW, BG.YELLOW),
            (0x88, 0x88, 0x88, FG.GRAY, BG.GRAY),

            (0x44, 0x44, 0xff, FG.BLUE | FG.INTENSITY, BG.BLUE | BG.INTENSITY),
            (0x44, 0xff, 0x44, FG.GREEN | FG.INTENSITY, BG.GREEN | BG.INTENSITY),
            (0x44, 0xff, 0xff, FG.CYAN | FG.INTENSITY, BG.CYAN | BG.INTENSITY),
            (0xff, 0x44, 0x44, FG.RED | FG.INTENSITY, BG.RED | BG.INTENSITY),
            (0xff, 0x44, 0xff, FG.MAGENTA | FG.INTENSITY, BG.MAGENTA | BG.INTENSITY),
            (0xff, 0xff, 0x44, FG.YELLOW | FG.INTENSITY, BG.YELLOW | BG.INTENSITY),

            (0x44, 0x44, 0x44, FG.BLACK | FG.INTENSITY, BG.BLACK | BG.INTENSITY),
            (0xff, 0xff, 0xff, FG.GRAY | FG.INTENSITY, BG.GRAY | BG.INTENSITY),
        ]
864275
def highlight_differences(s1, s2, color):
    """"""
    ls1, ls2 = len(s1), len(s2)

    diff_indices = [i for i, (a, b) in enumerate(zip(s1, s2)) if a != b]

    print(s1)

    if ls2 > ls1:
        colorise.cprint('_' * (ls2-ls1), fg=color)
    else:
        print()

    colorise.highlight(s2, indices=diff_indices, fg=color, end='')

    if ls1 > ls2:
        colorise.cprint('_' * (ls1-ls2), fg=color)
    else:
        print()
103266
def calculate_colors(self, values):
        """"""
        # set domain if it is not set
        _flattenedList = list(flatten(values))
        if not self.is_domain_set:
            self.set_domain(_flattenedList)

        _flattenedColors = range(len(_flattenedList))
        for count, value in enumerate(_flattenedList):
            _flattenedColors[count] = self.calculate_color(value)

        return unflatten(values, iter(_flattenedColors))
342850
def flatten_colors(colors):
    """"""
    all_colors = {"wallpaper": colors["wallpaper"],
                  "alpha": colors["alpha"],
                  **colors["special"],
                  **colors["colors"]}
    return {k: util.Color(v) for k, v in all_colors.items()}
83591
def gradient_list(start, end, steps):
    """"""
    delta = [end[i] - start[i] for i in range(4)]
    return [bytearray(start[j] + (delta[j] * i) // steps for j in range(4))
            for i in range(steps + 1)]
994934
function(list, map, legendSize) {
            var hexColor;
            this.colorList = [];
            this.hcConfig.colors = [];
            for(i = 0; i < list.length; i++) {
                hexColor = this.colorPalette.getColor(list[i], map[list[i]], legendSize);
                this.colorList.push(hexColor);
                this.hcConfig.colors.push(this.colorUtils.addAlphaToColor(hexColor, 1.0));
            }
        }
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)
1357923
def normalize_rgb_colors_to_hex(css):
    """"""

    regex = re.compile(r"rgb\s*\(\s*([0-9,\s]+)\s*\)")
    match = regex.search(css)
    while match:
        colors = [s.strip() for s in match.group(1).split(",")]
        hexcolor = '#%.2x%.2x%.2x' % tuple(map(int, colors))
        css = css.replace(match.group(), hexcolor)
        match = regex.search(css)
    return css
216819
def moreland_interpolate_sampled (srgb1, srgb2, refwhite=CIELAB_D65,
                                  nsamples=DEFAULT_SAMPLE_POINTS):
    """"""

    msh1, msh2 = srgb_to_msh (np.asarray ([srgb1, srgb2],
                                          dtype=np.float), refwhite)

    raddiff = msh1[H] - msh2[H]
    while raddiff > np.pi:
        raddiff -= 2 * np.pi
    while raddiff < -np.pi:
        raddiff += 2 * np.pi
    raddiff = np.abs (raddiff)

    x = np.linspace (0, 1, nsamples).reshape ((nsamples, 1))
    x = np.repeat (x, 3, 1)

    if msh1[S] <= 0.05 or msh2[S] <= 0.05 or raddiff < np.pi/3:
        # Colors are too close together to comfortably put white in between.
        # Our interpolation won't have a control point, and won't actually be
        # divergent.

        if msh1[S] < 0.05 and msh2[S] > 0.05:
            msh1[H] = moreland_adjusthue (msh1, msh1[M])
        elif msh2[S] < 0.05 and msh1[S] > 0.05:
            msh2[H] = moreland_adjusthue (msh2, msh2[M])

        samples = np.empty ((4, nsamples))

        msh = (1 - x) * msh1 + x * msh2
        samples[0] = x[:,0]
        samples[1:4] = msh_to_srgb (msh, refwhite).T
    else:
        # Colors are not too close together -- we can add a white control
        # point in the middle, and do two interpolations joined piecewise. We
        # then use 2*nsamples-1 (not actually nsamples -- shhh) samples for
        # the spline fit

        msh3 = msh2
        msh2a = np.asarray ([np.max ([msh1[M], msh3[M], 88]), 0, 0])
        msh2b = msh2a.copy ()

        if msh1[S] < 0.05 and msh2a[S] > 0.05:
            msh1[H] = moreland_adjusthue (msh2a, msh1[M])
        elif msh2a[S] < 0.05 and msh1[S] > 0.05:
            msh2a[H] = moreland_adjusthue (msh1, msh2a[M])

        if msh2b[S] < 0.05 and msh3[S] > 0.05:
            msh2b[H] = moreland_adjusthue (msh3, msh2b[M])
        elif msh3[S] < 0.05 and msh2b[S] > 0.05:
            msh3[H] = moreland_adjusthue (msh2b, msh3[M])

        samples = np.empty ((4, 2*nsamples-1))

        msh = (1 - x) * msh1 + x * msh2a
        samples[0,:nsamples] = 0.5 * x[:,0]
        samples[1:4,:nsamples] = msh_to_srgb (msh, refwhite).T

        msh = (1 - x) * msh2b + x * msh3
        samples[0,nsamples-1:] = 0.5 * x[:,0] + 0.5
        samples[1:4,nsamples-1:] = msh_to_srgb (msh, refwhite).T

    return samples
401311
function toColor(v1, v2, v3, v4, v5) {
    var _r, _g, _b, _a, R, G, B, rgb, options;
    if (v1 === undefined) {
        _r = _g = _b = 0;
        _a = 1;
    } else if (Array.isArray(v1)) {
        options = v2 || {};
        _r = v1[0] !== undefined ? v1[0] : 0;
        _g = v1[1] !== undefined ? v1[1] : 0;
        _b = v1[2] !== undefined ? v1[2] : 0;
        _a = v1[3] !== undefined ? v1[3] : options.base || 1;
    } else if (v1.r !== undefined) {
        options = v2 || {};
        _r = v1.r;
        _g = v1.g;
        _b = v1.b;
        _a = v1.a !== undefined ? v1.a : options.base || 1;
    } else if (typeof v1 === 'string') {
        if (v1.indexOf('#') === 0) {
            return v1;
        }
        if (v1.indexOf('rgb') === 0) {
            return v1;
        }
        if (colors.indexOf(v1) !== -1) {
            return v1;
        }
    } else if (typeof v1 === 'number') {
        if (arguments.length === 1) { // Grayscale value
            _r = _g = _b = v1;
            _a = 1;
        } else if (arguments.length === 2) { // Gray and alpha or options
            _r = _g = _b = v1;
            if (typeof v2 === 'number') {
                _a = v2;
            } else {
                options = v2;
                _a = options.base || 1;
            }
        } else if (arguments.length === 3) { // RGB or gray, alpha and options
            if (typeof v3 === 'number') {
                _r = v1;
                _g = v2;
                _b = v3;
                _a = 1;
            } else {
                _r = _g = _b = v1;
                _a = v2;
                options = v3;
            }
        } else if (arguments.length === 4) { // RGB and alpha or options
            _r = v1;
            _g = v2;
            _b = v3;
            if (typeof v4 === 'number') {
                _a = v4;
            } else {
                options = v4 || {};
                _a = options.base || 1;
            }
        } else { // RGBA + options
            _r = v1;
            _g = v2;
            _b = v3;
            _a = v4;
            options = v5;
        }
    }

    if (!(typeof _r === 'number' &&
        typeof _g === 'number' &&
        typeof _b === 'number' &&
        typeof _a === 'number')) {
        throw new Error('Invalid color arguments');
    }

    options = options || {};

    // The base option allows you to specify values in a different range.
    if (options.base !== undefined) {
        _r /= options.base;
        _g /= options.base;
        _b /= options.base;
        _a /= options.base;
    }
    R = Math.round(_r * 255);
    G = Math.round(_g * 255);
    B = Math.round(_b * 255);
    return 'rgba(' + R + ', ' + G + ', ' + B + ', ' + _a + ')';
}
725308
def saturateHexColor(hexcolor, adjustment = 1.0):
	''''''
	assert(adjustment >= 0 and len(hexcolor) >= 1)
	prefix = ""
	if hexcolor[0] == '#':
		hexcolor = hexcolor[1:]
		prefix = "#"
	assert(len(hexcolor) == 6)
	
	if adjustment == 1.0:
		return "%s%s" % (prefix, hexcolor)
	else:
		hsvColor = list(colorsys.rgb_to_hsv(int(hexcolor[0:2], 16)/255.0, int(hexcolor[2:4], 16)/255.0, int(hexcolor[4:6], 16)/255.0))
		hsvColor[1] = min(1.0, hsvColor[1] * adjustment)
		rgbColor = [min(255, 255 * v) for v in colorsys.hsv_to_rgb(hsvColor[0], hsvColor[1], hsvColor[2])]
		return "%s%.2x%.2x%.2x" % (prefix, rgbColor[0], rgbColor[1], rgbColor[2])
758395
function(color1, color2) {
		var result = color1.slice();
		for (var i=0;i<3;i++) {
			for (var j=1;j<arguments.length;j++) {
				result[i] += arguments[j][i];
			}
		}
		return result;
	}
1282339
def add_interpolated_colorbar(da, colors, direction):
    
    # Special case that arises due to not so useful
    # aesthetic mapping.
    if len(colors) == 1:
        colors = [colors[0], colors[0]]

    # Number of horizontal egdes(breaks) in the grid
    # No need to create more nbreak than colors, provided
    # no. of colors = no. of breaks = no. of cmap colors
    # the shading does a perfect interpolation
    nbreak = len(colors)

    if direction == 'vertical':
        mesh_width = 1
        mesh_height = nbreak-1
        linewidth = da.height/mesh_height
        # Construct rectangular meshgrid
        # The values(Z) at each vertex are just the
        # normalized (onto [0, 1]) vertical distance
        x = np.array([0, da.width])
        y = np.arange(0, nbreak) * linewidth
        X, Y = np.meshgrid(x, y)
        Z = Y/y.max()
    else:
        mesh_width = nbreak-1
        mesh_height = 1
        linewidth = da.width/mesh_width
        x = np.arange(0, nbreak) * linewidth
        y = np.array([0, da.height])
        X, Y = np.meshgrid(x, y)
        Z = X/x.max()

    # As a 2D coordinates array
    coordinates = np.zeros(
        ((mesh_width+1)*(mesh_height+1), 2),
        dtype=float)
    coordinates[:, 0] = X.ravel()
    coordinates[:, 1] = Y.ravel()

    cmap = ListedColormap(colors)
    coll = mcoll.QuadMesh(mesh_width, mesh_height,
                          coordinates,
                          antialiased=False,
                          shading='gouraud',
                          linewidth=0,
                          cmap=cmap,
                          array=Z.ravel())
    da.add_artist(coll)
499264
public void interpolateColorValue( ByteBuffer cmapBuffer, int cell ) {
        cmapBuffer.put(cell == Integer.MAX_VALUE ? blank : getColor((float) cell));
    }