function _inc(
var x: Integer): Integer;
begin
Result := x;
inc(x);
end;
function Gradient2( ACanvas: TCanvas;
Pos: TRect;
const Colors:
Array of Integer ): Boolean;
var
x: Integer;
NewColor: Integer;
Percent: Single;
rOP, gOP, bOP: Single;
// One Percent
cOldID, cID: Integer;
xPercent, OnePercent: Cardinal;
begin
Result := False;
{Initialization}
Pos.Right := Pos.Right - Pos.Left;
// Right = Width
Pos.Bottom := Pos.Bottom - Pos.Top;
// Bottom = Height
with ACanvas
do
begin
cOldID := -1;
cID := 0;
xPercent := High(Colors);
if xPercent < 1
then
Exit;
OnePercent := Pos.Right
div xPercent;
for x := 1
to Pos.Right
do
begin
if x-OnePercent >= OnePercent*cOLDID
then
begin
cOldID := _inc(cID);
rOP := (GetRValue(Colors[cID])-GetRValue(Colors[cOldID])) / OnePercent;
gOP := (GetGValue(Colors[cID])-GetGValue(Colors[cOldID])) / OnePercent;
bOP := (GetBValue(Colors[cID])-GetBValue(Colors[cOldID])) / OnePercent;
end;
NewColor :=
RGB(
GetRValue(Colors[cOldID])+Round(rOP*(x
mod OnePercent)),
GetGValue(Colors[cOldID])+Round(gOP*(x
mod OnePercent)),
GetBValue(Colors[cOldID])+Round(bOP*(x
mod OnePercent))
);
Pen.Color := NewColor;
MoveTo( Pos.Left+x, Pos.Top );
LineTo( Pos.Left+x, Pos.Top+Pos.Bottom );
end;
end;
Result :=
not Result;
end;