[Python] Remake color mixing function to find color to mix with given color to get the given...

Discussão em 'Python' iniciado por Stack, Abril 26, 2025.

  1. Stack

    Stack Membro Participativo

    My question looks very strange, but I'll try my best to explain it. I got this function

    def combine_hex_values(d):
    d_items = sorted(d)
    tot_weight = 2
    red = int(sum([int(k[:2], 16) for k in d_items])/tot_weight)
    green = int(sum([int(k[2:4], 16) for k in d_items])/tot_weight)
    blue = int(sum([int(k[4:6], 16) for k in d_items])/tot_weight)
    zpad = lambda x: x if len(x)==2 else '0' + x
    return zpad(hex(red)[2:]) + zpad(hex(green)[2:]) + zpad(hex(blue)[2:])


    you paste 2 colors like this:

    print(combine_hex_values({"FF79FF ", "4c34eb"}))


    and you get resulting color a556f5. So basically it works like this: color1+color2 = result. What I want is to find color2 when color1 and result are known. So, imagine we know the result color is white and color1 is blue. How to make a function which would calcuate color2 to mix with color1 to get result color? (the color we mix with color1) ?

    Continue reading...

Compartilhe esta Página