Core Function PixelSearch

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
Line 1: Line 1:
 
<pre>
 
<pre>
PixelSearch ( <left>, <top>, <right>, <bottom>, <colour>, <shade>, <step> )
+
PixelSearch ( <left>, <top>, <right>, <bottom>, <colour>, <shade>, <padding>, <step> )
 
</pre>
 
</pre>
  
Line 34: Line 34:
  
 
Default is 0 (exact match).
 
Default is 0 (exact match).
 +
 +
==== padding ====
 +
 +
Optional; A range of pixels to search around any *found* pixels for example a pad of 1 will cause an area of like 2x2x2 to be scanned instead of just the 1 pixel.
 +
 +
Default is 0 (no padding).
  
 
==== step ====
 
==== step ====

Revision as of 03:16, 11 December 2011

PixelSearch ( <left>, <top>, <right>, <bottom>, <colour>, <shade>, <padding>, <step> )

Contents

Description

Searches a rectangle of pixels for the pixel colour provided.

Parameters

left

left coordinate of rectangle.

top

top coordinate of rectangle.

right

right coordinate of rectangle.

bottom

bottom coordinate of rectangle.

colour

Colour value of pixel to find (in decimal or hex).

shade

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).

padding

Optional; A range of pixels to search around any *found* pixels for example a pad of 1 will cause an area of like 2x2x2 to be scanned instead of just the 1 pixel.

Default is 0 (no padding).

step

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.

Return Value

Success: Returns a two-element array of pixel's coordinates. (Array[0] = x, Array[1] = y)

Failure: Returns 0.

Remarks

The search is performed top-to-bottom, left-to-right, and the first match is returned.

RGB is used to define colours by default but this can be changed using the ColourMode option.

Performing a search of a region can be time consuming, so use the smallest region you are able to reduce CPU load.

See "PixelCoordMode" in Opt

Example

$coord = PixelSearch( 35, 99, 600, 600, 0x0000ff );
If ( $coord )
{
	MsgBox("X and Y are: $coord[0] , $coord[1]");
}
Else
{
	MsgBox("not found");
}
 
// OR
List ($x, $y) = PixelSearch( 35, 99, 600, 600, 0x0000ff );
If ( $x && $y ) // It is true this will fail a match at coordinate 0,0 but its unlikely that it would matter
{
	MsgBox("X and Y are: $x, $y");
}
Else
{
	MsgBox("not found");
}
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox