PDA

View Full Version : Universal AutoColor function



Cazax
02-28-2008, 12:53 PM
My first function:
function FindMyColor(Color,Tol : Integer) : Integer;
var
x,y,YourColor,U,K : Integer;
begin
MarkTime(U);
if FindColorTolerance(x, y, Color, MMX1, MMY1, MMX2, MMY2, Tol) then
begin
YourColor := GetColor(x,y);
Writeln('Your Color = '+ IntToStr(YourColor));
K := TimeFromMark(U);
Writeln('Took '+ IntToStr(K)+' mscs');
Result := YourColor;
end else
begin
Writeln('Could not find your color!');
end;
end;


Your Color = 2130293
Took 31 mscs
Successfully executed

JuKKa
02-28-2008, 01:11 PM
function FindMyColor(Var X, Y: Integer; Color, X1, Y1, X2, Y2, Tol: Integer) : Integer;
begin
if FindColorSpiralTolerance(x, y, Color, X1, Y1, X2, Y2, Tol) then
begin
Result := GetColor(X, Y);
Writeln('Your Color = '+ IntToStr(Result));
end else
Writeln('Could not find your color!');
end;

A bit shorter. Now people can choose where to start searching for the color, and where. with alot less code ;)

n3ss3s
02-28-2008, 01:46 PM
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:


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 :)

Cazax
02-28-2008, 01:50 PM
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:


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 :)

nice. thanks, i have to learn with this.