views:

301

answers:

5

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 accomplish this?

+1  A: 

white in RGB is 255,255,255

So, just decrese red and green

ralu
+1  A: 

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

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

Moishe
+5  A: 

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.

webguydan
The question was about white to blue, not blue to white.
ndim
+1  A: 
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.

paxdiablo
+3  A: 

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

ndim