That would get the color of any color it found within the tolerance, not as accurate as could be, - this is how we autocolor where I live:
SCAR Code:
Function Mean(Values: TExtendedArray): Extended;
Var
I: Integer;
Begin
For I := 0 To High(Values) Do
Result := Result + Values[i];
Result := Result / GetArrayLength(Values);
End;
Function UpdateColorFromArray(Ref: Integer; Colors: TIntegerArray): Integer;
Var
Dif: Array of Array [0..2] Of Extended;
HSL, HSL2: Array [0..2] Of Extended;
SortedDif: TExtendedArray;
C, I, L, D: Integer;
R: Extended;
Begin
ColorToHSL(Ref, HSL[0], HSL[1], HSL[2]);
SetArrayLength(Dif, GetArrayLength(Colors));
L := High(Colors);
For I := 0 To L Do
Begin
ColorToHSL(Colors[i], HSL2[0], HSL2[1], HSL2[2]);
For C := 0 To 2 Do
Dif[i][c] := Abs(HSL[c] - HSL2[c]);
End;
L := High(Dif);
SetArrayLength(SortedDif, L + 1);
For D := 0 To L Do
SortedDif[d] := Mean([Dif[d][0], Dif[d][1], Dif[d][2]]);
R := AMinE(SortedDif);
For C := 0 To L Do
If SortedDif[c] = R Then
Begin
Result := Colors[c];
Exit;
End;
End;
Function AutoColorMMFlax: Boolean;
Var
Colors: TIntegerArray;
Purple: TPointArray;
tmp: Integer;
Begin
FindColorsPie(Purple, mmFR, 75, 0.0, 359.0, 1.0, 75.0, MMX1, MMY1, MMX2, MMY2, MMCX, MMCY);
Colors := GetColors(Purple);
ClearSameIntegers(Colors);
tmp := UpdateColorFromArray(mmFR, Colors);
If tmp <> 0 Then
Result := True;
If Result Then
mmFR := tmp;
End;
Use FindColorsSpiralTolerance to get all the coloured points within the tolerance, then do a GetColors so you have the colors of the points, then a ClearSameIntegers so you only have one instance of every color, and then, sort out the closest color to the ref