SRL Archive - SRL Development and Help

findColorsSpiralTolerance - Multiple colors?


TomTop

2015-01-22 14:19:33

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

2015-01-22 14:39:57

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

2015-01-23 02:03:19

From: Camel
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

2015-01-23 04:27:58

From: TomTop
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

2015-01-23 05:19:02

From: bonsai
 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

2015-01-23 05:21:38


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

2015-01-23 05:36:34

From: slacky

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

2015-01-23 06:23:22

From: TomTop
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

2015-01-23 12:35:48

From: bonsai
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

2015-01-25 19:20:22

From: TomTop
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.