I\'m making a small collection of types/functions related to gradients for future use. I would like to make sure there\'s at least two procedures: ColorBetween and ColorsBet
I don't know if this is the fastest way, but it works:
function ColorBetween(const ColorA, ColorB: TColor; const Percent: Integer): TColor;
var
R1, G1, B1: Byte;
R2, G2, B2: Byte;
begin
R1:= GetRValue(ColorA);
G1:= GetGValue(ColorA);
B1:= GetBValue(ColorA);
R2:= GetRValue(ColorB);
G2:= GetGValue(ColorB);
B2:= GetBValue(ColorB);
Result:= RGB(
Percent * (R2-R1) div 100 + R1,
Percent * (G2-G1) div 100 + G1,
Percent * (B2-B1) div 100 + B1
);
end;
function ColorsBetween(const ColorA, ColorB: TColor; const Count: Integer): TColorArray;
var
X : integer;
begin
SetLength(Result, Count);
for X := 0 to Count - 1 do
Result[X] := ColorBetween(ColorA, ColorB, Round((X / (Count-1)) * 100)); //Note: Divide by count-1
end;