开发者

What is rgb formula for a gradient going from white to blue?

I want to have a button that has numbers in the range 0 ... 255. I'd like the color of the button to be white when it's zero and blue (RGB = (0,0,255)) when it is 255. How can I accomplish this? At first I tried to make it RGB = (0,0,0) in the beginning, but it will only make it black.

How can I a开发者_开发百科ccomplish this?


Simple linear interpolation between white (255,255,255) and blue (0,0,255) will do.


A gradient from blue to white would start with:

0,0,255

with values of the R and G increasing at the same rate: 1,1,255 ... 10,10,255 ... 255,255,255

The colors between the 2 will start to appear pastel blue, then greyish blue.


whitebluegradient(n):
    if n <   0: n = 0
    if n > 255: n = 255
    r = 255-n
    g = r
    b = 255
    return rgb (r,g,b)

This will give (255,255,255 = white) for n = 0 and (0,0,255 = blue) for n = 255.


white in RGB is 255,255,255

So, just decrese red and green


Set R & G to (255 - the value of the button).

255,255,255 = white 0,0,255 = blue

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜