Solved

Color to fade from bright red to dark red with RGB-function

Posted on 2003-10-26
2
456 Views
Last Modified: 2012-05-04
Hi,
I think this a quite easy question for an expert, but I do not manage it:
In a database I have a field where items are in that are awaited for a certain date. If the items are not back by that date the row is paint in red. Now I want that the color is not only red but a certain tone of red depending on the days the item is not in time for ex. the item is in delay for 100 days, the row is dark red, for 50 days a lighter red and so on. I tried with: brush.color:= RGB(255,0,0) and that's OK only with red. How must I insert the RGB-values to have different shades of red ?
0
Comment
Question by:SCHUCla74
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 8

Expert Comment

by:gmayo
ID: 9622474
255 is full brightness, 0 is nil. So use a value in between 0 and 255 for varying degrees of brightness. If you only use the first value, that is the red. Use a calculation to get degrees of redness for number of days.

Example:
if (DaysLate <= 0) then begin
   Brush.Color := clWhite;
end else if (DaysLate <= 100) then begin
   Brush.Color := RGB(Round(((100-DaysLate)/100) * 255), 0, 0);
end else begin
   Brush.Color := clBlack;
end;

Which gives a white background if DaysLate is zero or less, varying degrees of red to black for 1 - 100 days late, and black for over 100 days late. Alter to suit your requirements.

Geoff M.
0
 
LVL 8

Accepted Solution

by:
gmayo earned 100 total points
ID: 9622475
Actually, maybe you mean white to red. In which case that should be:
if (DaysLate <= 0) then begin
  Brush.Color := clWhite;
end else if (DaysLate <= 100) then begin
  v := Round(((100-DaysLate)/100) * 255);
  Brush.Color := RGB(255, v, v);
end else begin
  Brush.Color := clRed;
end;

Geoff M.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
When I am typing into a TEdit last word repeats 7 175
Run video youtube webbrowse 10 85
Delphi: Connect to running MS Outlook 4 199
CheckListBox usage 3 96
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question