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.
SCAR Code:
{*******************************************************************************
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;