# Pixelsearch nub question

## Recommended Posts

Maybe it's not as noob as I think it is, but I sure am stumped .

What I want to do is search pretty much my entire screen for the color red.

Yes, I know how to do this part .:

$Coords=PixelSearch(121, 135, 885, 600, 12059395, 5) If NOT @error Then If BitAND(GUICtrlRead($Radio1), $GUI_CHECKED) =$GUI_CHECKED then
MouseClick("left",$Coords[0]+10,$Coords[1]+20,1,0)
Sleep(900)
Else
MouseClick("right",$Coords[0]+10,$Coords[1]+20,1,0)
Sleep(1900)
EndIf
Else
Scream()
EndIf

BUT what I'm stumped on is how to have it not read a box perimeter around the center of my screen. So something in equation sense like: PixelsearchA - PixelsearchB = PixelSearchC.... Which A being the entire screen, B being that box perimeter I DON'T WANT it to search, and C being the resulting shape.

I drew a diagram to give you guys a better idea of what I want... :S

Edited by UnknownWarrior

##### Share on other sites

see, what u can do is this:

do a pixel search for the entire screen.. this will return u the array with co-ordinates..

Now check the co-ordinates.. are they falling in the while area marked, if yes, exclude them..

if ($x,$y) are the co-ordinates of left top corner of white area to be ignored, and the white area is say 100x100, in dimensions.. then check if the pixelsearch x coords is not less than $x, and not greater than ($x+100), similar for y co-ord..

like this:

$Coords=PixelSearch(121, 135, 885, 600, 12059395, 5) if$Coords[0] < $x and$Coords[0] > ($x+100) Then Ignore() if$Coords[1] < $y and$Coords[1] > ($y+100) Then Ignore() If NOT @error Then If BitAND(GUICtrlRead($Radio1), $GUI_CHECKED) =$GUI_CHECKED then
MouseClick("left",$Coords[0]+10,$Coords[1]+20,1,0)
Sleep(900)
Else
MouseClick("right",$Coords[0]+10,$Coords[1]+20,1,0)
Sleep(1900)
EndIf
Else
Scream()
EndIf

[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

##### Share on other sites

hmmm would it be possible, if you have to search for a circle or a rectangle, that pixelsearch finds the middle of it instead of starting at the topper left corner ?

##### Share on other sites

Its possible for the rectrangle.. just like the square as i said above..

u just add the length to x co-ordinate.. and breadth to y.. plain n simple geometry..

I'll have to think about the circle.. but u can do something using the same concept.. just give me some time..

[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

##### Share on other sites

see, what u can do is this:

do a pixel search for the entire screen.. this will return u the array with co-ordinates..

Now check the co-ordinates.. are they falling in the while area marked, if yes, exclude them..

if ($x,$y) are the co-ordinates of left top corner of white area to be ignored, and the white area is say 100x100, in dimensions.. then check if the pixelsearch x coords is not less than $x, and not greater than ($x+100), similar for y co-ord..

like this:

$Coords=PixelSearch(121, 135, 885, 600, 12059395, 5) if$Coords[0] < $x and$Coords[0] > ($x+100) Then Ignore() if$Coords[1] < $y and$Coords[1] > ($y+100) Then Ignore() If NOT @error Then If BitAND(GUICtrlRead($Radio1), $GUI_CHECKED) =$GUI_CHECKED then
MouseClick("left",$Coords[0]+10,$Coords[1]+20,1,0)
Sleep(900)
Else
MouseClick("right",$Coords[0]+10,$Coords[1]+20,1,0)
Sleep(1900)
EndIf
Else
Scream()
EndIf

Well what would be needed in the Ignore() Func then? I considered this idea too, but what can I put in the Ignore() then?

Also, will this, in theory, work?

Edit: Also, do you mean $x meaning the top left coordinates, and y being the down right coordinates of my white region that I don't want searched? Cause it couldn't be done with just one coordinate could it? :S Edited by UnknownWarrior #### Share this post ##### Link to post ##### Share on other sites here's what u can do for the circle.. say$x,$y are the centre points.. and$Coord[0],$Coord[1] are the pixelsearch points.. what u can do is that u can find the length of the line in between these two points.. by using the Distance Formula.. But this is valid only when the line is slanted and not vertical or horizontal.. If u want to apply this for a straight line, u can check if either$x=$Coord[0] or$y=$Coord[1].. if either of these are same.. the line will be straight.. then u can just subtract the cordinates which are not the same from eachother to get the distance between these two points.. After finding the length between the two points.. just check if it is greater than the radius.. if lesser than (inside the circle) or equal to (on the circle).. then exclude it from search.. It's a bit complex.. but it will do the job [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com #### Share this post ##### Link to post ##### Share on other sites Well what would be needed in the Ignore() Func then? I considered this idea too, but what can I put in the Ignore() then? Also, will this, in theory, work? Edit: Also, do you mean$x meaning the top left coordinates, and y being the down right coordinates of my white region that I don't want searched? Cause it couldn't be done with just one coordinate could it? :S

Hey, I just put Ignore() for understanding.. I didn't mean that u put sumthing in it.. U can put nothing.. n still it will work..

This works in theory.. I haven't tested.. buti can't find a reason why it shouldn't..

N $x,$y are the x and y coordinates of the left top corner.. just 1 point.. got it??

[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

##### Share on other sites

Ok I'm having a little trouble imagining all this.

$x+100 and$y+100 won't be the exact numbers I need... So how can I find the numbers I need there?

Do I get the x,y coord on the top and on the right of the white region? Or the Top left, down right? Etc... I need to make it a certain length and width for what I'm using it for...

[The top LEFT of the white region is: 408, 226... The CENTER of the region is: 513, 336]

Edit: Ok so I saw your other post, but will it know still not to check say the down right part of the white region as well? Beings your only going from the center to the top left...?

Edited by UnknownWarrior

##### Share on other sites

I think we have created a lot of confusion, when it's all just so simple..

see the left top corner is 408,226..

the length of white rectrangle is.. 210.. from what i take.. and breadth is 200..

So the pixel search x-coordinate should not be in the region from 408 to 618. and y shudn't be in 226 to 426..

so it coord[0] can be less than 408, i.e less than $x, and can be more than 618, i.e ($x+$l),$l is length of rectrangle..

same for coord[1]..

got it??

[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

##### Share on other sites

what if you dont have a fixed point.

like a rectangle which can be dynamic in width and height.

and then from the upper left to the bottom right with "for" f.e.

##### Share on other sites

I think we have created a lot of confusion, when it's all just so simple..

see the left top corner is 408,226..

the length of white rectrangle is.. 210.. from what i take.. and breadth is 200..

So the pixel search x-coordinate should not be in the region from 408 to 618. and y shudn't be in 226 to 426..

so it coord[0] can be less than 408, i.e less than $x, and can be more than 618, i.e ($x+$l),$l is length of rectrangle..

same for coord[1]..

got it??

I think I got it solved, but a little different.

$Coords=PixelSearch(139, 139, 901, 611, 12059395, 5);610 425... up 400, 256 If$Coords[0] < $x+100 and$Coords[1] < $y+100 Then$first = 1
ElseIf $Coords[0] >$x-110 and $Coords[1] >$y+110 AND $first = 1 Then$first = 0
Ignore()
ElseIf NOT @error Then
If BitAND(GUICtrlRead($Radio1),$GUI_CHECKED) = $GUI_CHECKED then MouseClick("left",$Coords[0]+10,$Coords[1]+20,1,0) Sleep(900) Else MouseClick("right",$Coords[0]+10,$Coords[1]+20,1,0) Sleep(1900) EndIf Else Scream() EndIf With your way, you had it comparing with < and > with$x on the same line. Well it may be true on that X, but you don't want Ignore() to come in unless y is true too... Which is why I made it this way.

Edited by UnknownWarrior

##### Share on other sites

please put it like this.. ur script wont work in some cases..

$x<$Coords[0] < $x+100 and$y<$Coords[0] <$x+100

Ignore the syntax.. understand my point..

[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

##### Share on other sites

please put it like this.. ur script wont work in some cases..

$x<$Coords[0] < $x+100 and$y<$Coords[0] <$x+100

Ignore the syntax.. understand my point..

THATS different from what you said before (ignoring your typo of putting 2 $x+100)... Before you did: If$x<Coords Then Ignore()

Well before it even has a chance to CHECK for the y point also, it could already go to the Ignore() and mess it all up.

What you put up there is the same thing as mine, just a little simpler...

##### Share on other sites

hey man it wasn't a typo.. it was just the syntax for this: $x<$Coords[0] < $x+100.. thats y u r seeing two x's in the same line..$x<$Coords[0] <$x+100 is broken up into $x<$Coords[0] and $x+100>$Coords[0]

$y<$Coords[1] < $y+100 is broken up into$y<$Coords[1] and$y+100>$Coords[1] This defines the white area range in terms of x and y.. It wasn't any typo.. I agree with u that it shudn't go into ignore() before checking y.. But what u r saying is not the same as mine.. u r just considering the$Coords[0]<x+100 case and totally ignoring $Coords[0]>x.. Which u shudn't.. So in the end its 4 ands.. 1)$Coords[0] > $x 2)$Coords[0] < ($x+100) 3)$Coords[1] > $y 4)$Coords[1] < ($y+100) Then Ignore() [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com #### Share this post ##### Link to post ##### Share on other sites hey man it wasn't a typo.. it was just the syntax for this:$x<$Coords[0] <$x+100.. thats y u r seeing two x's in the same line..

$x<$Coords[0] < $x+100 is broken up into$x<$Coords[0] and$x+100>$Coords[0]$y<$Coords[1] <$y+100 is broken up into $y<$Coords[1] and $y+100>$Coords[1]

This defines the white area range in terms of x and y..

It wasn't any typo..

I agree with u that it shudn't go into ignore() before checking y..

But what u r saying is not the same as mine.. u r just considering the $Coords[0]<x+100 case and totally ignoring$Coords[0]>x..

Which u shudn't..

So in the end its 4 ands..

1) $Coords[0] >$x

2) $Coords[0] < ($x+100)

3) $Coords[1] >$y

4) $Coords[1] < ($y+100)

Then Ignore()

please put it like this.. ur script wont work in some cases..

$x<$Coords[0] < $x+100 and$y<$Coords[0] <$x+100

Ignore the syntax.. understand my point..

And I do have 4 Ands

1 x and 1 y

If $Coords[0] <$x+100 and $Coords[1] <$y+100 Then

and 2nd x and 2nd y

ElseIf $Coords[0] >$x-110 and $Coords[1] >$y+110 AND $first = 1 Then #### Share this post ##### Link to post ##### Share on other sites and 2nd x and 2nd y ElseIf$Coords[0] > $x-110 and$Coords[1] > $y+110 AND$first = 1 Then

[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

Kinda hard to explain, but I thought it out and it seems to work... As you move your mouse up left, it decreases in x and y... as you move it down right it increases... So the first If statement means it checks $x+100 and$y+100 (down right 100 on each)... If the monster is less than (up left from that coordinate) then it goes to the ElseIf... It puts $first = 1 so it knows that it WAS less than on the first check.... Then it checks the point$x-100 and $y-100 (up left 100 on each)... If its found STILL (the red color) it goes to ignore, otherwise it goes to the final ElseIf which clicks on the red color. #### Share this post ##### Link to post ##### Share on other sites ok.. so u r considering x,y as ur central point.. N now unfortunately u made a typo.. haha.. its infectitous or or what?? ElseIf$Coords[0] > $x-110 and$Coords[1] > $y+110 AND$first = 1 Then

Fine, so it does work, finally..

k let's close this 1..

[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

##### Share on other sites

ok.. so u r considering x,y as ur central point..

N now unfortunately u made a typo.. haha.. its infectitous or or what??

Fine, so it does work, finally..

k let's close this 1..

You are right... That should be \$y-110

##### Share on other sites

so is ur problem finally solved.. give me a final confirmation..

[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

## Create an account

Register a new account

×

• Wiki

• Back

• Git