SRL Archive - OSR Help

How can i ignore single pixels


marc2333

2012-11-06 14:36:10

So here is what i want my script to do :

I want it to find the color 12345678 and then check if it finds more of the color 12345678 just arround the first place it found the color. This way, if my script find a single pixel and can't find more pixel of this color in a short range, it will skip it and look somewhere else.

I taught about this :

if FindColor(X, Y, 12345678, 0, 0, 500, 500) then
if FindColor(X, Y, 12345678, X-10, Y-10, X+10, Y+10) then
begin
bla bla bla
end;

^ this would only check for 1 other pixel and i would need to repeat it like 10 times for example if i want to check if there is 10 pixels of the same color around the first it found.

My question :
Is there a way to do it much more simple ? (pretty sure there is one but can,t find what).
And is there a way i could script it so if it can't find enough pixel of the same color around the first pixel, then it go to an other one and not keep going on the same ?

Thanks, i hope i was clear =/

Olly

2012-11-06 14:39:47

Il make you (a basic) example but I recommend you look into TPA + ATPAs tutorials they make this kind of stuff very easy!

Procedure Test;
var
x, y: integer;
tpa : tpointarray;
begin
if FindColor(X, Y, 12345678, 0, 0, 500, 500) then //if you find your single pixel
if FindColors(TPA, 12345678, x-10, y-10, x+10, x+10) then //findcolors stores the points it finds in a tpa (an array of points!)
begin
if length(TPA) > 10 then //length is the length of the array which is our tpa, so if the tpa is greater than 10 pixels it will carry on!
begin
writeln('there are more than 10 pixels around the single colour point!');
mmouse(X,Y,5,5)
etc....
end else
writeln('there wasnt more than 10 pixels of colour around the first point!');
end;
end

marc2333

2012-11-06 14:46:21

I was closer then i could taught ! :) Thanks alot and i'll look at TPA. I knew how to use em on eclipse but gotta learn it again for simba.

P1ng

2012-11-06 14:47:32

I would do something very similar, but with the addition of the TPA function that sorts the points from biggest to smallest. Sorry, temporary blank - But it shouldn't be hard to find

J J

2012-11-06 14:49:50

What Olly posted will work but as you are searching around the first pixel I suggest also moving the mouse to a spot either left or right around the pixel.

procedure Test;
var
X, Y: Integer;
TPA: TPointArray;

begin
if FindColor(X, Y, 12345678, 0, 0, 500, 500) then
if FindColors(TPA, 12345678, X-10, Y-10, X+10, Y+10) then
if length(TPA) > 10 then
begin
WriteLn('there are more than 10 pixels around the single colour point!');
MMouse(X, Y, RandomRange(-5, 5), RandomRange(-5, 5));
// ETC
end;
end;

Oh yeah and Olly you accidently put X+10 twice instead of changing it to Y+10 for the Y value. Other than that, will work the way you want it to work.

EDIT:
For this
From: P1ng
I would do something very similar, but with the addition of the TPA function that sorts the points from biggest to smallest. Sorry, temporary blank - But it shouldn't be hard to find


You can split the TPA into smaller TPA's based on distance (SplitTPA -> Array of TPointArray AKA ATPA). Then sort the ATPA on size SortATPASize(ATPA, True); But I don't think that is needed right now, according to your post :P

Olly

2012-11-06 14:58:24

This is a more advanced one, should sort the second problem out aswell "And is there a way i could script it so if it can't find enough pixel of the same color around the first pixel, then it go to an other one and not keep going on the same ?"

Im not good at explaining things so i still strongly suggest you read some tutorials :p

rocedure Test;
var
x, y, i: integer;
tpa : tpointarray;
ATPA: T2DPointArray;
begin
FindColors(TPA, 12345678, 0, 0, 500, 500);

SplitTPAWrap(TPA,10,ATPA); //splits the tpa up if the distance between one and other is greater than 10! also turns it into an ATPA
SortATPASize(ATPA,True); //this will sort the biggest one (with most points in) first

For I := 0 to High(ATPA) do
begin
If Length(ATPA[i]) > 10 Then //if length is greater than 10, if it isnt it will keep looping though the atpa looking
begin
Writeln('we found it!');
MiddleTPAEx(ATPA[i],X,Y); //you will want to get the middle of the points and set it as X/Y
MMouse(X,Y,5,5); //then move your mouse there
Exit; //dont forget to exit to avoid looping though the atpa if we dont need to anymore!
end;
end;
end;

marc2333

2012-11-06 16:20:39

Thanks to all of you, i should get something really good with all this. Learned something too ! :)

footballjds

2012-11-06 17:28:48

ATPA's are your best bet. I'd make you a function but ATPA's are all about how you sort them so I can't really do that unless i know the exact scenario.