SRL Archive - Help and Support

Autocoloring Question


itSchRis917

2008-05-13 01:48:45

So, i just followed Cazax's autocoloring tutorial: http://www.villavu.com/forum/showthread.php?t=29072. And im afraid my function doesnt fully work.. Or work at all for that matter.. Can someone take a look at my code and see if they see anything wrong with it?


const
ExtendedDebug = True;

var
i, c, b, a, cx, cy : integer;
ColorList: Integer;
RangePoints:TPointArray;
RangePoint:TPoint;
Range2DSplit : T2DPointArray;
Furnace: Integer;
C1 : TIntegerArray;

function AutoColorRange: Integer;
var
R, G, B: Integer;
H, S, L: Extended;
X, Y, Z: Extended;
begin
if not LoggedIn then exit;
Furnace := 7963267;
cx := MSCX;
cy := MSCY;
for C := 0 to 10 do
begin
FindColorsSpiralTolerance(cx, cy, RangePoints, Furnace, MSX1, MSY1, MSX2, MSY2, C);
if(Length(RangePoints) - 1 >= 10)then
Break;
end;

Range2DSplit := SplitTPA(RangePoints, 4);
for i := 0 to Length(Range2DSplit) - 1 do
begin
if not LoggedIn then exit;
SortATPAFrom(Range2DSplit, IntToPoint(MSCX, MSCY));
RangePoint:= MiddleTPA(Range2DSplit[i]);
if (ExtendedDebug) then
begin
Writeln('Found '+IntToStr(GetArrayLength(RangePoints))+' possible points.');
Writeln('Split into '+IntToStr(Length(Range2DSplit) - 1)+ ' T2DPointArrays.');
end;

C1 := GetColors(RangePoints);
for a := 0 to Length(C1) - 1 do
begin

begin
cx := RangePoint.x;
cy := RangePoint.y;
ColorList := GetColor(RangePoints[a].X, RangePoints[a].Y);
//if SimilarColors(ColorList, Furnace, 50) then
begin

ColorToRGB(ColorList, R, G, B);
ColorToHSL(ColorList, H, S, L);
ColorToXYZ(ColorList, X, Y, Z);
if InRange(R - G, 95, 155) then
if InRange(R - B, 109, 169) then
if InRange(G - B, -16, 44)then
if InRange(Round(S) - Round(H), -46, -16) then
if InRange(Round(L) - Round(H), -61, -31) then
if InRange(Round(S) - Round(L), -6, 34) then
if InRange(Round(X) - Round(Y), -10, 10) then
if InRange(Round(Y) - Round(Z), -15, 5 ) then
if GetColor(RangePoints[a].X + 2, RangePoints[a].Y + 2) = ColorList then
if GetColor(RangePoints[a].X + 1, RangePoints[a].Y + 1) = ColorList then
begin
Writeln('MyColor = '+Inttostr(ColorList));
Result := ColorList;
Exit;
end;
end;
end;
end;
Writeln('Couldnt find My Color!');
Result := 0;
end;
end;

Sir R. M8gic1an

2008-05-13 02:20:38


for a := 0 to Length(C1) - 1 do
High(C1) is better there.

what is the error?


i think this might be the problem:

for C := 0 to 10 do
begin
FindColorsSpiralTolerance(cx, cy, RangePoints, Furnace, MSX1, MSY1, MSX2, MSY2, C);
if(Length(RangePoints) - 1 >= 10)then
Break;
end;
finding one color with tolerance 10 might not be enough, so if it doesn't find the color here it'll just run everything else with an empty TPA.

if i were you i'd debug the function to find out where it's going wrong. and i would also use ACA2 to choose a better color and i wouldn't have a FindColorsSpiralTol in a loop, especially not with such a small diff.
maybe…


for C := 1 to 5 do
begin
FindColorsSpiralTolerance(cx, cy, RangePoints, Furnace, MSX1, MSY1, MSX2, MSY2, C*5);
if(Length(RangePoints) - 1 >= 10)then
Break;
end;

notice C starting from 1 and in the FindColors C*5


~RM

itSchRis917

2008-05-13 07:46:09

I still dont get the point of High(C1).. How does it make a difference?? The second piece of code you posted, you misinterpreted. That means that if i find more than 10 points(which it always does. last time i ran it it found 87 points and split it into 7 T2DPointArrays) then it breaks that loop. I really dont think it has anything to do with the top procedure i think it all has to do with the InRange and stuff..

Sir R. M8gic1an

2008-05-13 08:17:46

Length(array) := High(array) - Low(array) - 1;

the only reason i suggested high is because it's faster. i'll later have a look at the rest then…

~RM

Timothegreat

2008-05-13 16:31:17

actually its Length(array) := High(array) - Low(array) + 1;

an array from 0 to 2 is a length of 3.
2-0+1 = 3

Cazax

2008-05-13 17:23:53

for i := 0 to Length(Range2DSplit) - 1 do
begin
if not LoggedIn then exit;
SortATPAFrom(Range2DSplit, IntToPoint(MSCX, MSCY));
RangePoint:= MiddleTPA(Range2DSplit[i]);
if (ExtendedDebug) then
begin
Writeln('Found '+IntToStr(GetArrayLength(RangePoints))+' possible points.');
Writeln('Split into '+IntToStr(Length(Range2DSplit) - 1)+ ' T2DPointArrays.');
end;

C1 := GetColors(RangePoints);
for a := 0 to Length(C1) - 1 do
You dont need to start 2 loops. Also try expanding your range.

itSchRis917

2008-05-14 19:10:35

Ehh im not gonna worry about converting it to RGB and stuff, my function currently finds it no problem right now.. Thanks though guys.