How to fade color

后端 未结 8 1286
我寻月下人不归
我寻月下人不归 2021-02-06 05:56

I would like to fade the color of a pixel out toward white, but obviously maintain the same color. If I have a pixel (200,120,40), will adding 10 to each value to m

8条回答
  •  情书的邮戳
    2021-02-06 06:28

    Simply linearly interpolate between your color and white:

    def lerp(a, b, t):
        return a*(1 - t) + b*t
    
    import numpy as np
    white = np.array([255, 255, 255])
    my_color = np.array([...])
    lightened25 = lerp(my_color, white, 0.25)
    

    Or without numpy:

    lightened25 = [lerp(c, w, 0.25) for c, w in zip(my_color, white)]
    

提交回复
热议问题