calculate a colour gradient

M

Mark Light

Hi,
I have a tk.scale bar for which I want the background to change from
blue to red as I slide along it. The mechanics of this I can do, but
the colour gradient I have is very crude - basically the amount of R in
RGB just increases whilst the G and B are fixed values. Whilst this is
not really a python question does anybody have any suggestions about
calculating the RGB values for a smooth colour gradient?


Mark.
 
?

=?ISO-8859-1?Q?Gr=E9goire_Dooms?=

Mark said:
Hi,
I have a tk.scale bar for which I want the background to change from
blue to red as I slide along it. The mechanics of this I can do, but
the colour gradient I have is very crude - basically the amount of R in
RGB just increases whilst the G and B are fixed values. Whilst this is
not really a python question does anybody have any suggestions about
calculating the RGB values for a smooth colour gradient?

Have a look at the HSV color space and HSV -> RGB conversion:
http://en.wikipedia.org/wiki/HSV_color_space

Then linearly adjust the H while you slide the bar.

HTH,
 
P

Paul McGuire

Mark Light said:
Hi,
I have a tk.scale bar for which I want the background to change from
blue to red as I slide along it. The mechanics of this I can do, but
the colour gradient I have is very crude - basically the amount of R in
RGB just increases whilst the G and B are fixed values. Whilst this is
not really a python question does anybody have any suggestions about
calculating the RGB values for a smooth colour gradient?


Mark.
What about:
scale R from 255 to 0
scale B from 0 to 255 (or compute as 255-R)
hold G constant (try values like 0, 64, and 128 to brighten or darken the
resulting reds and blues)

-- Paul
 
M

Max M

Paul said:
What about:
scale R from 255 to 0
scale B from 0 to 255 (or compute as 255-R)
hold G constant (try values like 0, 64, and 128 to brighten or darken the
resulting reds and blues)

Or just use the websafe colors:

http://www.lynda.com/hexpalette/images/nhue2.gif


They basically us any combination of R,G,B with the values 00,11,22...
to ...DD,EE,FF

Easy to calculate and figure out.

regards Max M
 
S

Scott David Daniels

Mark said:
Hi,
I have a tk.scale bar for which I want the background to change from
blue to red as I slide along it. The mechanics of this I can do, but
the colour gradient I have is very crude - basically the amount of R in
RGB just increases whilst the G and B are fixed values. Whilst this is
not really a python question does anybody have any suggestions about
calculating the RGB values for a smooth colour gradient?


Mark.

Depending on the purpose, you could: search for "color temperature"
or "black body radiation" to get a very defensible transition, or
(for false-color or some such), break the range into pieces and do
a linear interpolation inside each piece. Play with R-O-Y-G-B, for
example. Note: even intervals is not going to look right, eyeball
the boundaries.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,201
Messages
2,571,051
Members
47,656
Latest member
rickwatson

Latest Threads

Top