function Gradient( ACanvas: TCanvas;
Pos: TRect;
const FromColor, ToColor: Cardinal ): Boolean;
var
x: Integer;
NewColor: Cardinal;
Percent: Single;
rOP, gOP, bOP: Single;
// One Percent
begin
Result := False;
{Initialization}
Pos.Right := Pos.Right - Pos.Left;
// Right = Width
Pos.Bottom := Pos.Bottom - Pos.Top;
// Bottom = Height
with ACanvas
do
begin
rOP := (GetRValue(ToColor)-GetRValue(FromColor)) / Pos.Right;
gOP := (GetGValue(ToColor)-GetGValue(FromColor)) / Pos.Right;
bOP := (GetBValue(ToColor)-GetBValue(FromColor)) / Pos.Right;
for x := 1
to Pos.Right
do
begin
NewColor :=
RGB( GetRValue(FromColor)+Round(rOP*x),
GetGValue(FromColor)+Round(gOP*x),
GetBValue(FromColor)+Round(bOP*x) );
Pen.Color := NewColor;
MoveTo( Pos.Left+x, Pos.Top );
LineTo( Pos.Left+x, Pos.Top+Pos.Bottom );
end;
end;
Result :=
not Result;
end;