SRL Archive - SRL Archives

function FindAllColorsInBoxTolerance


Roberty Bob

2006-07-02 11:22:51

Another One I made just now. I know this can be helpful for you :)
I don't know if someone has already shared a similar function. :rolleyes:

For my exact autocolors, this works absolutely perfect on zero tolerance, never a misclick or unplanned random mouse movement again. :)

but if your colors aren't exact, I put the tolerance in for you!! It seems to work beautifully.

Its currently designed for main screen object finding, but easily changed :P but you can think of it as a potential bitmap / DTM substitute.

Example… pass in an array of several unique bank symbol colors, boxsize of 30, tolerance 30. bingo, I'm sure you will find the bank symbol every time, in milliseconds. Its really fast too, as it only needs to perform the several small ColorSpiral procedures.

note: a more advanced version could also refine the below… but I didn't want to overclutter it.
[PHP]
x:= MSCX-250+random(500);
y:= MSCY-200+random(400);
[/PHP]
A more advanced version could refine this with addition of a DistFromPlayer parameter etc.

ENJOY :D (lol… I also attached an example of this in action too. I do it for any function I make :P )

[PHP]
{*******************************************************************************
function FindAllColorsInBoxTolerance(var x,y: integer; ColorArray: array of Integer; BoxSize,Tol:integer):boolean;
By: Roberty Bob
Description: Pass in an array of object colors with principal reference color in Array[0]
Returns true if all the colors were found in a box surrounding the principal reference color.
*******************************************************************************}
function FindAllColorsInBoxTolerance(var x,y: integer; ColorArray: array of Integer; BoxSize,Tol:integer):boolean;

var
i,j,a,b,HBox,ArraySize,Sx,Sy,Ex,Ey: integer;
var
AllFound,ColorMissing: boolean;

begin
//******** Set these to your specific search area, to make function more efficient.
Sx:= MSX1; //currently main screen
Sy:= MSY1;
Ex:= MSX2;
Ey:= MSY2;
//********
HBox:= (BoxSize/2);
ColorMissing:= false;
AllFound:= false;
ArraySize:= GetArrayLength(ColorArray);
x:= MSCX-250+random(500);
y:= MSCY-200+random(400);

repeat
FindColorSpiralTolerance(x,y,ColorArray[0],Sx,Sy,Ex,Ey,Tol);
a:= x;
b:= y;
i:= 0;
repeat
if FindColorSpiralTolerance(a,b,ColorArray,a-(HBox),b-(HBox),a+(HBox),b+(HBox),Tol) then
AllFound:=true
else
begin
ColorMissing:= true;
AllFound:= false;
break;
end;

i:= i+1;
until i= (ArraySize-1)
if ColorMissing then break;
j:= j+1;
until AllFound or (j=10)

result:= AllFound;
end;
[/PHP]

WhiteShadow

2006-07-02 17:48:54

Nice, you've been making some 1337 stuff, with arrays. Great works. (:

Avaphi

2006-07-02 18:10:24

yes, he has been whipping out very 1337 stuff since he joined the team.. especially his autocolor !

The Prince of Randomness?

2006-07-02 19:25:55

Good work.

Renax

2006-07-03 14:50:40

FindColorsTolerance(x, y, Color, x1, y1, x2, y2, tolerance)

it's been done, its already a scar function.

Roberty Bob

2006-07-03 18:44:17

Hey Renax, I still can't find the function you mention by a normal search.

My Function first finds the principal color in a reference array that is input… ie. Array[0]

then after finding it… only returns true if all other (whether 1 or 1000) reference input colors are found in the box surrounding the occurence of the principal color.

Please confirm if you still think there is a scar function for this… I thought there was only one to place every color from a box into a TPoint Array.

:confused:

I would still has made this anyway… but just wouldn't have posted, is all.

Renax

2006-07-03 21:27:27

i guess i didn't pay enough attention to your description, yours is unique

Cruel

2006-07-04 00:53:30

I'd be suprised if no one came up with this idea in the past.
Anyways, speaking of FindColorsTolerance function… I decided to write an addition function that could be used… similar to this one.
It just like the original except that it returns an array of all the points that match all the requirements. And I added a 'min' parameter so you can decided the minimum number of colors that need to match in order to pass and be added to the returned array. (set it to 0 to make it so all colors have to be found)
[php]procedure AddPoint(var arr:TPointArray; p:TPoint);
begin
SetArrayLength(arr,GetArrayLength(arr)+1);
arr[GetArrayLength(arr)-1]:=p;
end;

function FindAllColorsInBoxTolerance2(var PointArray: TPointArray; ColorArray: array of Integer; BoxSize,min,Tol:integer):boolean;
var
i,i2,cnt,HBox,ArraySize1,ArraySize2,Sx,Sy,Ex,Ey: integer;
MainPoints,GoodPoints: TPointArray;
MatchArray: array of Byte;
begin
//******** Set these to your specific search area, to make function more efficient.
Sx:= MSX1; //currently main screen
Sy:= MSY1;
Ex:= MSX2;
Ey:= MSY2;
//********
x:= MSCX-250+random(500);
y:= MSCY-200+random(400);
//get point array of main color (ColorArray[0])
FindColorsSpiralTolerance(x,y,MainPoints,ColorArray[0],Sx,Sy,Ex,Ey,Tol);
HBox:= (BoxSize/2);
Result:= False;
ArraySize1:= GetArrayLength(ColorArray);
ArraySize2:= GetArrayLength(MainPoints);
if ArraySize2 = 0 then exit;
if min = 0 then min:= ArraySize1;
//Check all colors with all the points in the MainPoints array
//And add them to the GoodPoints intermediate array before they
//are eventually added, in order, into the main (PointArray) array.
for i:= 0 to ArraySize2 - 1 do begin
cnt:= 0;
for i2:= 0 to ArraySize1 - 1 do
if FindColorTolerance(x,y,ColorArray[i2],MainPoints.x-HBox,MainPoints.y-HBox,MainPoints.x+HBox,MainPoints.y+HBox,Tol) then
cnt:= cnt + 1;
if cnt >= min then begin
AddPoint(GoodPoints,MainPoints);
SetArrayLength(MatchArray,GetArrayLength(MatchArray)+1);
MatchArray[GetArrayLength(MatchArray)-1]:=cnt;
end;
end;
if GetArrayLength(GoodPoints) = 0 then exit;
Result:= True;
//add points in order of match count (highest first)
for i:= ArraySize1 downto min do
for i2:= 0 to GetArrayLength(GoodPoints) - 1 do
if MatchArray[i2] = i then AddPoint(PointArray,GoodPoints[i2]);
end;[/php]
This should work, but I haven't tested it… so likely to have a little something wrong with it.
And you'll probably want to edit it so that it doesn't add multiple points to the array that are in the same area… I just thought about that… I forgot. :P