예제 #1
0
def fix_color(card):
    if 'blackText' in card:
        del card['blackText']
    if 'art' in card:
        if 'body' in card['art']:
            if 'vertx' in card['art']['body']:
                card['art']['body']['vertex'] = card['art']['body']['vertx']
                del card['art']['body']['vertx']
    if 'color' in card:
        r255, g255, b255 = card['color']
        r = r255 / 255.0
        g = g255 / 255.0
        b = b255 / 255.0
        del card['color']
    elif 'art' in card:
        r = card['art']['primary']['r']
        g = card['art']['primary']['g']
        b = card['art']['primary']['b']
    else:
        return card

    primary_hex = rgb_to_hex(r, g, b)
    # complement = get_complementary(primary_hex)
    (h, s, l) = rgb_to_hsl(r, g, b)
    # (ch, cs, cl) = hex_to_hsl(complement)
    primary = (r, g, b)
    secondary, _, shadow = map(hex_to_rgb, color_in_between(primary_hex, hsl_to_hex(h, s, _STROKE_HSL[2]), 3))
    highlight = hex_to_rgb(color_in_between(primary_hex, hsl_to_hex(h, 1.0, 1.0), 2)[0])
    body_c = hex_to_rgb(text_color(primary_hex))

    if 'art' not in card:
        card['art'] = OrderedDict()
    art = card['art']

    for (name, rgb) in (
            ('primary', primary), ('secondary', secondary), ('shadow', shadow), ('highlight', highlight)):
        if name not in art:
            art[name] = OrderedDict()
        r, g, b = rgb
        a = 1.0
        art[name]['r'] = r
        art[name]['g'] = g
        art[name]['b'] = b
        art[name]['a'] = a
    if 'body' not in art:
        art['body'] = OrderedDict()
    body = art['body']
    if 'vertex' not in body:
        body['vertex'] = OrderedDict()
    vertex = body['vertex']
    vertex['r'] = body_c[0]
    vertex['g'] = body_c[1]
    vertex['b'] = body_c[2]
    vertex['a'] = 1.0
    return card
def fix_dict(in_dict):
    new_dict = OrderedDict()
    for k in ORDER:
        if k not in in_dict:
            continue
        new_dict[k] = fix_value(in_dict[k])
    for k in sorted(in_dict.keys()):
        if k in new_dict:
            continue
        new_dict[k] = fix_value(in_dict[k])

    return new_dict