jaberwacky Posted January 20, 2009 Posted January 20, 2009 (edited) Hello. I think that the parameters for PixelSearch() can be somewhat counter intuitive. So I wrapped PixelSearch such that all you have to do is to specify the center coordinates and the total height of the PixelSearch square. expandcollapse popup; #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($iX , $iY , $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. ; |1 - Color was not found. ; |2 - Coordinates must be at least one pixel away from the screen edge. ; |3 - $iShadeVariation out of bounds. ( 0 -- 255 ) ; |4 - $iHeight was out of bounds of the users screen. Resized to stay within screen edge. ; Author ........: Matthew R. G. ; Modified.......: ; Remarks .......: All quotes are from the helpfile. I got this idea from a 'Processing' language tutorial. (http://www.processing.org/) ; Related .......: PixelSearch ; Link ..........; (http://www.autoitscript.com/forum/index.php?showtopic=87319) ; Example .......; Yes ; ========================================================================================== #include-Once Local $iColor Local $iHalf Local $iHeight Local $iShadeVariation Local $iStep Local $iXYCoord[ 2 ] Local $iCenterX Local $iCenterY Local $iLeft Local $iTop Local $iRight Local $iBottom Local $sHWND Func _PixelSearchCenter($iCenterX,$iCenterY,$iHeight,$iColor,$iShadeVariation="",$iStep="",$sHWND="") $iHalf = $iHeight / 2 If $iCenterX = 0 And $iCenterY = 0 Then Return SetError( 2 ) ElseIf $iShadeVariation > 255 Then Return SetError( 3 ) ElseIf $iHalf > $iCenterX Then Return SetError( 4 ) EndIf $iLeft = $iCenterX - $iHalf $iTop = $iCenterY - $iHalf $iRight = $iCenterX + $iHalf $iBottom = $iCenterY + $iHalf $iXYCoord = PixelSearch($iLeft,$iTop,$iRight,$iBottom,$iColor,$iShadeVariation,$iStep,$sHWND) If @error = 1 Then Return SetError( 1 ) ElseIf @error = 0 Then Return $iXYCoord EndIf EndFuncoÝ÷ Øw«z+²x©¥ëh}ÊzØZ´¬yÛhµë-¶V®¶sb6æ6ÇVFRfÇCµõVÅ6V&66VçFW"æS2fwC° ¤FÒb33c·FVײ"ÒÒ²ÂÐ ¢b33c·FV×ÒõVÅ6V&66VçFW" ¤bW'&÷"ÒFVà¢6öç6öÆUw&FRb33c·FV׳ÒfײgV÷C²ÂgV÷C²fײb33c·FV׳Òfײ5$Äb¤VÇ6TbW'&÷"ÒFVà¢6öç6öÆUw&FRgV÷C´æ÷Bf÷VæBb333²gV÷C²fײ5$Äb¤VÇ6TbW'&÷"Ò"FVà¢6öç6öÆUw&FRgV÷Cµ7V&R×W7B&RBÆV7BöæRVÂg&öÒFRVFvRâgV÷C²fײ5$Äb¤VÇ6TbW'&÷"Ò2FVà¢6öç6öÆUw&FRgV÷C²b33c¶6FUf&Föâ÷WBöb&÷VæG2âÒÒ#SRgV÷C²fײ5$Äb¤VÇ6TbW'&÷"ÒBFVà¢6öç6öÆUw&FRgV÷C²b33c¶VvBv2÷WBöb&÷VæG2öbFRW6W'267&VVââgV÷C²fײ5$Äb¤VæD` ¤W@ Hope ya'll find it useful! Edited January 20, 2009 by jaberwocky6669 Helpful Posts and Websites: AutoIt Wiki | Can't find what you're looking for on the Forum? My scripts: Guiscape | Baroque AU3 Code Formatter | MouseHoverCalltips | SciTe Customization GUI | ActiveWindowTrack Toy | Monitor Configuration UDF
jaberwacky Posted January 24, 2009 Author Posted January 24, 2009 (edited) Ok, latest version now allows user to specify a width value. expandcollapse popup#cs #FUNCTION# ================================================================================ Name ....: _PixelSearchCenter Desc. ...: This UDF wraps PixelSearch in order to allow users to specify the center - coordinates and the height and width of the rectangle 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($iX , $iY , $iHeight , $iWidth , $iColor [ , $iShadeVariation = "" [ , $iStep = "" [ , $sHWND = "" ]]]) Params ..: $iCenterX -- X coordinate of PixelSearch center $iCenterY -- Y coordinate of PixelSearch center $iHeight -- The total height of the PixelSearch rectangle. $iWidth -- The total width of the PixelSearch rectangle. $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." RetVals ..: Success - The first set of coordinates of the desired color. Failure - Returns SetError(): |1 - Color was not found. |2 - Coordinates must be at least one pixel away from the screen edge. |3 - $iShadeVariation out of bounds. ( 0 -- 255 ) |4 - $iHeight was out of bounds of the users screen. |5 - $iWidth was out of bounds of the users screen. Author ..: Matthew R. Goude Remarks .: All quotes are from the helpfile. I got this idea from a 'Processing' language tutorial. Related .: PixelSearch Links ...; www.autoitscript.com/forum/index.php?showtopic=87319 www.autoitscript.com/forum/index.php?showtopic=88008 www.processing.org/learning/tutorials/basics/ Example .; Yes ========================================================================================== #ce #include-Once Local $iColor Local $iHalfHeight Local $iHalfWidth Local $iHeight Local $iShadeVariation Local $iStep Local $iXYCoord[ 2 ] Local $iCenterX Local $iCenterY Local $iLeft Local $iTop Local $iRight Local $iBottom Local $sHWND Func _PixelSearchCenter( $iCenterX , _ $iCenterY , _ $iHeight , _ $iWidth , _ $iColor , _ $iShadeVariation = "" , _ $iStep = "" , _ $sHWND = "" ) $iHalfHeight = $iHeight / 2 $iHalfWidth = $iWidth / 2 If $iCenterX = 0 And $iCenterY = 0 Then Return SetError( 2 ) ElseIf $iShadeVariation > 255 Then Return SetError( 3 ) ElseIf $iHalfHeight > $iCenterX Then Return SetError( 4 ) ElseIf $iHalfWidth > $iCenterY Then Return SetError( 5 ) EndIf $iLeft = $iCenterX - $iHalfHeight $iTop = $iCenterY - $iHalfHeight $iRight = $iCenterX + $iHalfWidth $iBottom = $iCenterY + $iHalfWidth $iXYCoord = PixelSearch( $iLeft , _ $iTop , _ $iRight , _ $iBottom , _ $iColor , _ $iShadeVariation , _ $iStep , _ $sHWND ) If @error = 1 Then Return SetError( 1 ) ElseIf @error = 0 Then Return $iXYCoord EndIf EndFunc Edited January 24, 2009 by jaberwocky6669 Helpful Posts and Websites: AutoIt Wiki | Can't find what you're looking for on the Forum? My scripts: Guiscape | Baroque AU3 Code Formatter | MouseHoverCalltips | SciTe Customization GUI | ActiveWindowTrack Toy | Monitor Configuration UDF
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now