function FindColorSpiralTolerance(var x,y: Integer; color, xs, ys, xe, ye,
tolerance: Integer; window: HWND): Boolean;
var
xx, yy, i, direction, length: Integer;
TestDC: HDC;
WndRECT: TRect;
label
Done;
begin
GetWindowRect(window, WndRECT);
xx := round((WndRECT.Right - WndRECT.Left) / 2);
yy := round((WndRECT.Bottom - WndRECT.Top) / 2);
TestDC := GetWindowDC(Window);
direction := 0;
length := 1;
if SimilarColors(color, GetPixel(TestDC, xx, yy), tolerance) then goto Done;
while not ((xx < xs) or (yy < ys) or (xx > xe) or (yy > ye)) do
begin
for i := 1 to length do
begin
case direction of
0: yy := yy - 1;
1: xx := xx + 1;
2: yy := yy + 1;
3: xx := xx - 1;
end;
if SimilarColors(color, GetPixel(TestDC, xx, yy), tolerance) then goto Done;
end;
direction := (direction + 1) mod 4;
if (direction mod 2) = 0 then length := length + 1;
end;
if SimilarColors(color, GetPixel(TestDC, xx, yy), tolerance) = False then
begin;
x := -1;
y := -1;
Result := False;
Exit
end;
Done:
x := xx;
y := yy;
Result := True;
end;