Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Keep same colors algorithm

Posted on 2004-10-11
2
Medium Priority
?
158 Views
Last Modified: 2010-04-05
I have for my button a color Color1 ( ex: $005200A4 ) . For border Color2 ( ex.$0036006C) and Color3 ( ex: $009428FF ).

The color2 is a dark Color1 and Color3 is the light Color1.

I wish to get instantly Color2/Color3 when change Color1 to have omolog dark/light color for the new Color1. Same darkness/lightness scale.

How to do that?
0
Comment
Question by:ginsonic
[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 7

Expert Comment

by:LRHGuy
ID: 12278264
The lower the number the "darker" the color (I think).

  $52  $00  $A4  is color 1
  $36  $00  $6C  is color2 (darker, lower numbers)
 -$1C -$00 -$38  subtract from normal color to get darker ... lowest number should be $00

  $94  $28  $FF  is color3 (lighter, higher numbers)
 +$42 +$28 +$5B  add to normal color to get lighter ... highest number should be $FF

You do need to deal with each piece of the color separately, as shown.

Just a thought...
0
 
LVL 7

Accepted Solution

by:
LRHGuy earned 2000 total points
ID: 12278394
This seems to work for me. You might want to play with the values being added/subtracted to get a good contrast...

type
  c1=record
      case integer of
       0:( p:array[0..3] of byte);
       1:(l:longint)
    end;

procedure MakeColors(aOrig:tColor; var aLighter, aDarker:TColor);
var
  C,L,D:c1;
  function Lighter(orig,add:byte):byte;
  begin
{$R-}
    result:=orig+add;
    if result<orig then
      result:=$ff; {full bright}
{$R+}
  end;
  function Darker(orig,add:byte):byte;
  begin
{$R-}
    result:=orig-add;
    if result>orig then
      result:=$00; {full dark}
{$R+}
  end;
begin
  C.l:=aOrig;
// make lighter color
  L.L:=C.L;
  L.p[1]:=lighter(C.p[1],$5B);
  L.p[2]:=lighter(C.p[2],$28);
  L.p[3]:=lighter(C.p[3],$42);
  aLighter:=L.L;
// make darker color
  D.L:=C.L;
  D.p[1]:=darker(C.p[1],$1c);
  D.p[2]:=darker(C.p[2],$1c);
  D.p[3]:=darker(C.p[3],$38);
  aDarker:=D.l;
end;

procedure TForm2.Button1Click(Sender: TObject);
var
  C,L,D:tColor;
begin
  self.color:=clYellow;
  makecolors(Self.Color,L,D);
  panel1.color:=L;
  radiogroup1.color:=D;
end;
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

722 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