PDA

View Full Version : findColorsSpiralTolerance - Multiple colors?



TomTop
01-22-2015, 07:19 PM
Hey,

I'm trying to use the following code to find multiple colors at the same time

findColorsSpiralTolerance(x, y, TPA, 8087871, mainScreen.getBounds(), 3, colorSetting(2, 0.25, 0.84));


I tried the following, but I kept getting an error.

findColorsSpiralTolerance(x, y, TPA, [8087871, 12427872], mainScreen.getBounds(), 3, colorSetting(2, 0.25, 0.84));



How can I get this function to work and to find multiple colors without having to do the following?

findColorsSpiralTolerance(x, y, TPA, 8087871, mainScreen.getBounds(), 3, colorSetting(2, 0.25, 0.84));
if (Length(TPA) < 1) then
findColorsSpiralTolerance(x, y, TPA, 12427872, mainScreen.getBounds(), 3, colorSetting(2, 0.25, 0.84));

Camel
01-22-2015, 07:39 PM
You would have to do 2 searches.

You could just do this.

findColorsSpiralTolerance(x, y, TPA, 8087871, mainScreen.getBounds(), 3, colorSetting(2, 0.25, 0.84));
findColorsSpiralTolerance(x, y, TPA2, 12427872, mainScreen.getBounds(), 3, colorSetting(2, 0.25, 0.84));
TPA := combineTPA(TPA,TPA2);

TomTop
01-23-2015, 07:03 AM
You would have to do 2 searches.

You could just do this.

findColorsSpiralTolerance(x, y, TPA, 8087871, mainScreen.getBounds(), 3, colorSetting(2, 0.25, 0.84));
findColorsSpiralTolerance(x, y, TPA2, 12427872, mainScreen.getBounds(), 3, colorSetting(2, 0.25, 0.84));
TPA := combineTPA(TPA,TPA2);



It's just the problem is I don't have to find two colors, I have probably 15.
So to repeat that 15 times.. :S

Is there any other better piece of code to find about 15 colors (In an array?) instead of having 15 lines, one for each color?

Thanks.

bonsai
01-23-2015, 09:27 AM
It's just the problem is I don't have to find two colors, I have probably 15.
So to repeat that 15 times.. :S

Is there any other better piece of code to find about 15 colors (In an array?) instead of having 15 lines, one for each color?

Thanks.

var
i: integer;
oneColor, allColors: TPointArray;
colors: TIntegerArray

colors := [66815,329215,263679,132351,1445887,198143,197887,
1642751,394751,1577215,460543,1643007,1117439];

for i := 0 to high(colors) do
if (findcolors(oneColor, colors[i], mainscreen.getBounds())) then
allColors.combine(oneColor);

TomTop
01-23-2015, 10:19 AM
var
i: integer;
oneColor, allColors: TPointArray;
colors: TIntegerArray

colors := [66815,329215,263679,132351,1445887,198143,197887,
1642751,394751,1577215,460543,1643007,1117439];

for i := 0 to high(colors) do
if (findcolors(oneColor, colors[i], mainscreen.getBounds())) then
allColors.combine(oneColor);

How would I go about implementing that?
By that I mean to get it to, for example, right click on each color found?

Thanks.

slacky
01-23-2015, 10:21 AM
function FindColorsTolEx(var TPA:TPointArray; colors:TIntegerArray; bounds:TBox; tol:Int32): Boolean;
var
i:Int32;
tmp:TPointArray;
begin
for i:=0 to High(colors) do
begin
FindColorsTolerance(tmp, colors[i], bounds, tol);
TPA := CombineTPA(TPA,tmp);
end;
Result := Length(TPA) <> 0;
end;

TomTop
01-23-2015, 10:36 AM
function FindColorsTolEx(var TPA:TPointArray; colors:TIntegerArray; bounds:TBox; tol:Int32): Boolean;
var
i:Int32;
tmp:TPointArray;
begin
for i:=0 to High(colors) do
begin
FindColorsTolerance(tmp, colors[i], bounds, tol);
TPA := CombineTPA(TPA,tmp);
end;
Result := Length(TPA) <> 0;
end;


How would I get that to right click on each color? And then if it findes an Option in the Choose option, to get it to exit the function?

My current script does that, it's just the color finding is very messed up, I think I understand how to implement bonsais code.. I think.

bonsai
01-23-2015, 11:23 AM
How would I get that to right click on each color? And then if it findes an Option in the Choose option, to get it to exit the function?

My current script does that, it's just the color finding is very messed up, I think I understand how to implement bonsais code.. I think.

Your example used the variable TPA. In my code, I gathered the color data into allColors. So whatever you did with TPA you could do with allColors.

My post was more of a hint to show you the idea of how to have the array, loop through it, and combine results into a single tpa. Your need is a little more complicated with tolerance/cts2 settings.

TomTop
01-23-2015, 05:35 PM
Your example used the variable TPA. In my code, I gathered the color data into allColors. So whatever you did with TPA you could do with allColors.

My post was more of a hint to show you the idea of how to have the array, loop through it, and combine results into a single tpa. Your need is a little more complicated with tolerance/cts2 settings.


There is a problem with your code, or atleast, how can I move the mouse the where the color is?

Janilabo
01-26-2015, 12:20 AM
There is a problem with your code, or atleast, how can I move the mouse the where the color is?bonsai already told you, you need to loop through the TPA which contains the found TPoint's (pixels).

Just a basic example:

function FindColorsTolEx(var TPA: TPointArray; colors: TIntegerArray; bounds: TBox; tol: Int32): Boolean;
var
i: Int32;
tmp: TPointArray;
begin
SetLength(TPA, 0);
for i := 0 to High(colors) do
if FindColorsTolerance(tmp, colors[i], bounds.X1, bounds.Y1, bounds.X2, bounds.Y2, tol) then
TPA := CombineTPA(TPA, tmp);
Result := (Length(TPA) > 0);
end;

var
found: TPointArray;
w, h, i: Integer;

begin
GetClientDimensions(w, h);
if FindColorsTolEx(found, [0, 255], IntToBox(0, 0, (w - 1), (h - 1)), 0) then
for i := 0 to High(found) do
MoveMouse(found[i].X, found[i].Y); // NOTE: Don't use MoveMouse in RuneScape!
end.