473,511 Members | 10,195 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

calculate a colour gradient

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.


Jul 18 '05 #1
4 5164
Mark Light wrote:
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,
--
Grégoire Dooms
Jul 18 '05 #2
"Mark Light" <li***@soton.ac.uk> wrote in message
news:ca**********@aspen.sucs.soton.ac.uk...
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
Jul 18 '05 #3
Paul McGuire wrote:
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
Jul 18 '05 #4
Mark Light wrote:
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.
--
-Scott David Daniels
Sc***********@Acm.Org
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2421
by: Woody Splawn | last post by:
I have a webform where I would like to have the background color for the webform be a gradient in blue. How do I do this? What is the easiest way? What is the way most used by other developers? ...
13
2052
by: Crirus | last post by:
The main ideea: I havea 513x513 array of values....I draw a sort of map using that values for colors... so I have a realistic lanscape (map). I want to zoom about 60 times that map...and the...
0
4425
by: Don | last post by:
I'm making a custom control that has a multiline textbox on it. I want to make the textbox have a gradient background. On my custom control's Paint event I call a routine that draws a gradient on...
11
4450
by: Maximus | last post by:
Hi all, Has anyone been able to reterive the gradient selection colors used in outlook 2003? Basically, I have a grid showing a list of records and my client wants the selected row to have the...
4
5868
by: Jon Slaughter | last post by:
I'm drawing a linear gradient and its very "banded". The colors are far enough part that it should be plenty smooth enough but I always get the same number of bands regardless. I've tried to set...
14
12618
by: Olw | last post by:
Hello, Does anyone have a nice link to some code for calculating the gradient of a function in C? Thanks, Olw
6
6152
by: moondaddy | last post by:
I want to fill the entire background of a page with a gradient. As a test, I first filled with a solid color like this: <body style="background-color: #ccffff;" > and the entire page was this...
9
8132
by: Eric Lindsay | last post by:
How do you provide a consistent gradient fill as a background in a liquid layout? If I make a gradient fill image say 1000 pixels wide (and repeat it down the page) to suit a typical computer...
1
5238
by: cmwb2000 | last post by:
Hi I am trying to calculate the radius of a circle of best fit from 2 or 3 mouse positions. At present I am recording a series of points a mouse passes, I intended to pick the first and last point...
0
7251
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7430
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7089
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5673
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5072
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1581
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
451
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.