[Python] Python find RGB values between 2 colours

Discussão em 'Python' iniciado por Stack, Maio 28, 2025.

  1. Stack

    Stack Membro Participativo

    Ive got two data points which are hex codes and im trying to find to set up a system to automatically find x amount of colours between the two colors and adding them to a list for later use. My current way of going about it is converting the values to RGB and calculating the difference between the R,G and B values then multiplying the difference by x up to the amount of colours I want but this is not working.

    import colormap
    import math

    limit = 5
    upper_color,lower_color = '#ff05ff','#380238'

    color_code = []
    ur,ug,ub = colormap.hex2rgb(upper_color)
    lr,lg,lb = colormap.hex2rgb(lower_color)

    for i in range(limit):
    r_dist = ur-lr
    g_dist = ug-lg
    b_dist = ub-lb

    color_code.append(colormap.rgb2hex(math.floor(abs((r_dist*(1+i/10)))),
    math.floor(abs((g_dist*(1+i/10)))),
    math.floor(abs((b_dist*(1+i/10))))))

    Continue reading...

Compartilhe esta Página