SRL Archive - SRL Archives

FindColorToleranceInc


Richard

2009-03-21 06:17:33

Very basic function, searchs for a color without having to worry about finding the right tolerance for it. Just enter the same as the normal FindColorTolerance, just put what you want the maximum tolerance to be instead of the static tolerance.

{*******************************************************************************
Function FindColorToleranceInc(Color: Integer; var x, y: Integer; xs, ys, xe, ye: Integer; MaxTolerance: Integer): Boolean;
By: Richard
Description: Searches for the color in the set area and increases the
tolerance until it finds the color or the maximum tolerance is reached.
*******************************************************************************}

Function FindColorToleranceInc(Color: Integer; var x, y: Integer; xs, ys, xe, ye: Integer; MaxTolerance: Integer): Boolean;
Var
tol : Integer;
Begin
tol := 0;
If (MaxTolerance <= -1) then
srl_Warn('FindColorToleranceInc', 'Tolerance cannot be below 0', warn_AllVersions);
For tol := 0 to (MaxTolerance - 1) do
Begin
If FindColorTolerance(x, y, Color, xs, ys, xe, ye, tol) then
Begin
Result := FindColorTolerance(x, y, Color, xs, ys, xe, ye, tol);
WriteLN('FindColorToleranceInc: '+IntToStr(tol)+' was the final tolerance');
Break;
end;
tol := tol + 1;
If (tol >= MaxTolerance) then
Begin
srl_Warn('FindColorToleranceInc', 'couldn'#39't find the color', warn_AllVersions);
Exit;
end;
end;
end;

Sir R. M8gic1an

2009-03-21 06:58:52

well, in this case tol = i, so no need to have both variables.

~RM

Richard

2009-03-21 07:07:01

Didn't think of that when scripting it, I'll edit it now.

nielsie95

2009-03-21 10:15:24


If FindColorTolerance(x, y, Color, xs, ys, xe, ye, tol) then
Begin
Result := FindColorTolerance(x, y, Color, xs, ys, xe, ye, tol); //Why a second search?
WriteLN('FindColorToleranceInc: '+IntToStr(tol)+' was the final tolerance');
Break;
end;
tol := tol + 1; //Why in a for-loop?
If (tol >= MaxTolerance) then //Why is this in the loop?
Begin
srl_Warn('FindColorToleranceInc', 'couldn'#39't find the color', warn_AllVersions);
Exit;
end;

Nava2

2009-03-21 13:33:47

function FindColorToleranceIncEx(var x, y: Integer; Color: Integer; xs, ys, xe, ye: Integer; MaxTolerance: Integer; var TheTol: Integer): Boolean;
var
tol: Integer;
begin
if (MaxTolerance < 0) then
srl_Warn('FindColorToleranceInc', 'Tolerance cannot be below 0', warn_AllVersions);
for tol := 0 to (MaxTolerance) do
begin
Result := FindColorTolerance(x, y, Color, xs, ys, xe, ye, tol);
if Result then
begin
TheTol := Tol;
WriteLn('FindColorToleranceInc: ' + IntToStr(tol) + ' was the final tolerance');
Exit;
end;
end;
WriteLn('Could not find the Color.');
end;

function FindColorToleranceInc(var x, y: Integer; Color: Integer; xs, ys, xe, ye: Integer; MaxTol: Integer): Boolean;
begin
Result := FindColorToleranceIncEx(x, y, Color, xs, ys, xe, ye, MaxTol, xs);
end;