SRL Archive - SRL Archives

Function AutoColorThisColor!


R0b0t1

2007-09-14 17:29:20

Should be able to use it for anything, but I want someone to test it along with me, so I can improve it :p.


program New;

function AutoColorThisColor(ThisColor, PrefTol, Accry: Integer): Integer;
Var
DidFind: Boolean;
I, x1, y1, Cnt, FirstCorr: Integer;
X, Y, Z, Xc, Yc, Zc: Extended;
AX, AY, AZ: Array [1..20] of Extended;
ColorAr: Array [0..21] of Integer;
SkipAr: Array [0..19] of TPoint;
begin
ColorAr[0]:= ThisColor;
For I:= 1 to 20 do
begin
DidFind:= FindColorSkipCoordsTolerance(x1, y1, ThisColor, MSX1, MSY1, MSX2, MSY2, 50, SkipAr);
If (DidFind) Then
begin
ColorAr[I]:= GetColor(x1, y1);
SkipAr[I].x:= x1;
SkipAr[I].y:= y1;
ColorToXYZ(ColorAr[I], AX[I], AY[I], AZ[I])
end;
end;
If (Accry > GetArrayLength(ColorAr)) Then
Accry:= GetArrayLength(ColorAr);
X:= AMaxE(AX);
Y:= AMaxE(AY);
Z:= AMaxE(AZ);
Xc:= X - AMinE(AX);
Yc:= Y - AMinE(AY);
Zc:= Z - AMinE(AZ);
FirstCorr:= 2;
For I:= 0 to (GetArrayLength(ColorAr) - 1) do
begin
If (AX[I] > (Xc - StrToFloat(IntToStr(PrefTol)))) and
(AX[I] < (X + StrToFloat(IntToStr(PrefTol)))) and
(AY[I] > (Yc - StrToFloat(IntToStr(PrefTol)))) and
(AY[I] < (Y + StrToFloat(IntToStr(PrefTol)))) and
(AZ[I] > (Zc - StrToFloat(IntToStr(PrefTol)))) and
(AZ[I] < (Z + StrToFloat(IntToStr(PrefTol)))) Then
begin
If (FirstCorr >= I) Then
FirstCorr:= I;
inc(Cnt);
end;
If (Cnt >= Accry) Then
Result:= XYZToColor(AX[FirstCorr], AY[FirstCorr], AZ[FirstCorr])
else
Result:= 0
end;

begin
end.

nielsie95

2007-09-15 03:15:40

Have you ran this? I get all kinds of compiling errors… You are trying to boolean an integer result..

n3ss3s

2007-09-15 05:33:31

Haha, good job robot, but yes except for that thing, you forgot making the autocoloring xD

R0b0t1

2007-09-16 14:34:11

Eh? WTF?

Hmm… I must have had my mind elsewhere. When I change the result it will become autocoloring!

But I sometimes put errors in there to see if people actually test it. And I see you did, but I didn't intend that :p.

EDIT: GARGH! Stupid SCAR… Some of these errors don't even make sense!

R0b0t1

2007-09-16 20:38:38

FIxed, it should compile now.