Example #1
0
def desaturate(byte):
    #print("---------------------------------")
    #print("Byte: "+byte)
    byte = byte[2:4] + byte[0:2]  #little endian smh
    bits = bin(int(byte, scale))[2:].zfill(num_of_bits)
    r_bits = bits[1:6]
    g_bits = bits[6:11]
    b_bits = bits[11:16]
    r_convert = hex(round(int(r_bits, base=2) * inverse_ratio))[2:].zfill(2)
    g_convert = hex(round(int(g_bits, base=2) * inverse_ratio))[2:].zfill(2)
    b_convert = hex(round(int(b_bits, base=2) * inverse_ratio))[2:].zfill(2)
    rgb_str = "#" + r_convert + g_convert + b_convert
    c = Color(rgb_str)
    #print("Initial colour: "+c.get_hex())
    temp_sat = c.saturation - 0.2
    if temp_sat <= 0:
        temp_sat = 0
    c.saturation = temp_sat
    new_rgb_str = c.get_hex().replace("#", "")
    if len(new_rgb_str) == 3:
        new_rgb_str = new_rgb_str[0] + new_rgb_str[0] + new_rgb_str[
            1] + new_rgb_str[1] + new_rgb_str[2] + new_rgb_str[2]

    #print("Adjusted colour: #"+new_rgb_str)
    new_r = bin(round(int(new_rgb_str[0:2], base=16) * ratio))[2:].zfill(5)
    new_g = bin(round(int(new_rgb_str[2:4], base=16) * ratio))[2:].zfill(5)
    new_b = bin(round(int(new_rgb_str[4:6], base=16) * ratio))[2:].zfill(5)
    final_bits = "0" + new_r + new_g + new_b
    final_byte = hex(int(final_bits, base=2))[2:].zfill(4)
    final_byte = final_byte[2:4] + final_byte[0:2]
    #print("Final byte: "+final_byte)
    return final_byte
Example #2
0
def randomize_hue(bg_hex):
    color_obj = Color(bg_hex)
    randomized = random.random()
    color_obj.hue = randomized
    sat = color_obj.saturation
    color_obj.saturation = sat+randomized if (sat+randomized) <= 0.5 else 0.5
    return color_obj.get_hex()
def get_color():
    infinite_color = itertools.cycle(go_and_back_colors)
    while True:
        current_color = next(infinite_color)
        new_color = Color()
        new_color.set_rgb(map(lambda x: x / 256, current_color))
        yield new_color.get_hex()
Example #4
0
def color_for_count(count: int) -> ColorStr:
    if not count:
        return Color('white').get_hex()
    c = Color('green')
    max = 10
    count_real = min(max, count)
    c.hue = (max - count_real) / max * 0.33
    c.saturation = 1.0
    c.luminance = 0.7
    return c.get_hex()
Example #5
0
def ref_to_color(ref):
    color = Color(hex=f"#{md5(ref.name.encode()).hexdigest()[2:8]}")
    if color.saturation < 0.6:
        color.saturation = 0.6
    elif color.saturation > 0.7:
        color.saturation = 0.7

    if color.luminance < 0.7:
        color.luminance = 0.7
    elif color.luminance > 0.9:
        color.luminance = 0.9
    return color.get_hex()
Example #6
0
def getColourScale(weight, max):
    col1 = Color("purple")
    if max == 0:
        return "", "#FFF"

    val = 1 - ((weight / max) * 0.6)
    text_col = ""

    if val < 0.2:
        text_col = "#FFF"

    col1.set_luminance(val)
    return text_col, col1.get_hex()
Example #7
0
def merge_colors(colors: List[str],
                 factors: List[float],
                 shouldUseHsl: bool = False) -> str:
    output = Color()
    for color, factor in zip(colors, factors):
        color = Color(color)
        if shouldUseHsl:
            output.hue += color.hue * factor
            output.saturation += color.saturation * factor
            output.luminance += color.luminance * factor
        else:
            output.red += color.red * factor
            output.green += color.green * factor
            output.blue += color.blue * factor
    return output.get_hex()
Example #8
0
def lighter_color(color: ColorStr) -> ColorStr:
    c = Color(color)
    h, s, l = c.get_hsl()
    l_new = l + (1.0 - l) * 0.5
    c.set_hsl((h, s, l_new))
    return c.get_hex()
Example #9
0
def darker_color(color: ColorStr) -> ColorStr:
    c = Color(color)
    h, s, l = c.get_hsl()
    l_new = l * 0.75  # l - (1.0-l)*0.5
    c.set_hsl((h, s, l_new))
    return c.get_hex()
Example #10
0
# pixel location of each column of colours
widths = [10, 30, 50, 70, 94, 114, 135, 160, 180, 200]
data = []
for shade, h in heights.items():
    for colour_category, w in enumerate(widths):
        tmp = img[h, w]
        r = tmp[2]
        g = tmp[0]
        b = tmp[1]
        color = Color(rgb=(r / 255, b / 255, g / 255))
        data.append({
            'theme_colorID': colour_category,
            'shade': shade,
            'rgb': (r, g, b),
            'rgb_scaled': (r / 255, g / 255, b / 255),
            'hex': color.get_hex()
        })
df = pd.DataFrame(data)


def fix_white(df):
    df['shade'] = pd.to_numeric(df['shade'])
    for p in df.itertuples():
        if p.theme_colorID == 0:
            if p.shade == 0.6:
                df.at[p.Index, 'shade'] = -0.1
            elif p.shade == 0.4:
                df.at[p.Index, 'shade'] = -0.2
            elif p.shade == 0.2:
                df.at[p.Index, 'shade'] = -0.3
            elif p.shade == -0.25: