# PixelSearch Modification?

## Recommended Posts

Hi!

I searched the forums and couldn't find a function that does this. Guess I didn't look hard enough?

Anyway, I hacked together a function that makes PixelSearch a little more user friendly. I hope I didn't overlook a similiar function in the helpfile. Instead of specifying two separate coordinates for the top left corner and the bottom right corner. Or as it is described in the helpfile as the top and bottom line or something or another. You can now specify the center of the PixelSearch square and the total height of the square.

My main reason to post is to see your thoughts and for you to suggest your improvements.

```; \$centerX & \$centerY = (X,Y) coordinates of the center of the rectangle
; \$height = height of the square from the top to bottom but not from the center of the square.

Local \$xyCoord[ 2 ]

Local \$halfHeight = \$height/2

Local \$left = \$centerX - \$halfHeight

Local \$top = \$centerY - \$halfHeight

Local \$right = \$centerX + \$halfHeight

Local \$bottom = \$centerY + \$halfHeight

Return \$xyCoord

EndFunc```
Edited by jaberwocky6669

##### Share on other sites

```; \$centerX & \$centerY = (X,Y) coordinates of the center of the rectangle
; \$height = height of the square from the top to bottom but not from the center of the square.

Local \$xyCoord[ 2 ]
Local \$half = \$height/2
Return \$xyCoord
EndFunc```

Edited by jaberwocky6669

##### Share on other sites

```; \$centerX & \$centerY = (X,Y) coordinates of the center of the square
; \$height = height of the square from the top to bottom but not from the center of the square.

Local \$xyCoord[ 2 ] = [0]
Local \$half = \$height/2
If @error = 1 Then
SetError( 1 )
Else
Return \$xyCoord
EndIf
EndFunc```

Edited by jaberwocky6669

##### Share on other sites

I followed some UDF formatting instructions that I found:

```#cs
#FUNCTION# ===============================================================================
Name...........: _PixelSearchCenter
Description ...: This UDF wraps PixelSearch in order to allow users to specify the center -
coordinates of a PixelSearch square and the height of the square instead -
of the slightly confusing:
"left coordinate of rectangle."
"top coordinate of rectangle."
"right coordinate of rectangle."
"bottom coordinate of rectangle."
This is more intuitive to those of us who are new to AutoIt and/or -
computer programming in general.
Syntax .........: _PixelSearchCenter(\$iCenterX, \$iCenterY, \$iHeight, \$iColor, \$iShadeVariation="", \$iStep="", \$sHWND="")
Parameters ....: \$iCenterX -- X coordinate of PixelSearch center
\$iCenterY -- Y coordinate of PixelSearch center
\$iHeight -- The total height of the PixelSearch square.
\$iColor -- "Colour value of pixel to find (in decimal or hex)."
\$iShadeVariation -- "[optional] A number between 0 and 255 to indicate the -
allowed number of shades of variation of the red, green, -
and blue components of the colour. Default is 0 (exact match)."
\$iStep -- "[optional] Instead of searching each pixel use a value larger than 1 to skip -
pixels (for speed). E.g. A value of 2 will only check every other pixel. Default is 1."
\$sHWND -- "[optional] Window handle to be used."
Return values .: Success - The first set of coordinates of the desired color.
Failure - Returns 0 and Sets @Error:
|0 - No error.
Author ........: Matthew R. Goude
Modified.......:
Remarks .......: All quotes are from the helpfile. -
I got this idea from a Processing language tutorial. (http://www.processing.org/)
Related .......: PixelSearch
Example .......; Yes
==========================================================================================
#ce

#include-Once

Local \$iColor = 0
Local \$iHalf = 0
Local \$iHeight = 0
Local \$iStep = 0
Local \$iXYCoord[ 2 ] = [ 0 ]
Local \$iCenterX = 0
Local \$iCenterY = 0
Local \$iLeft = 0
Local \$iTop = 0
Local \$iRight = 0
Local \$iBottom = 0
Local \$sHWND = ""

\$iHalf = \$iHeight/2
\$iLeft = \$iCenterX-\$iHalf
\$iTop = \$iCenterY-\$iHalf
\$iRight = \$iCenterX+\$iHalf
\$iBottom = \$iCenterY+\$iHalf
If @error = 0 Then
SetError( 0 )
Return \$iXYCoord
Else
SetError( 1 )
Return 0
EndIf
EndFunc```
Edited by jaberwocky6669

##### Share on other sites

Next idea: PixelSearch but within a circle! Just specify the screen coordinates of the center of the circle and the radius.

## Create an account

Register a new account

×

• Wiki

• Back

• Git