;___________________________________________
;GetMatrix(StartX,StartY,Dimension)
;FindMatrix(ScanStartX,ScanEndX,ScanStartY,ScanEndY,Dimension,Matrix)
;___________________________________________
;Tip : For faster searching, make sure the first pixel of matrix is
; not abundant on the screen
;example of 3x3 matrix
SetBatchLines, -1
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
SplashImage,, W185 H50 B1, Press F4 to grab Matrix at mouse position,,
KeyWait, F4, D
MouseGetPos, mX, mY
SplashImage, Off
Matrix := GetMatrix(mX,mY,3)
Result := FindMatrix(1,800,1,600,3,Matrix)
MsgBox, %Result%
StringSplit, Result, Result, %A_Space%
Loop, 5
{
SplashImage,, X%Result1% Y%Result2% W3 H3 B1 CWRed, .
Sleep, 500
SplashImage, Off
Sleep, 500
}
ExitApp
;___________________________________________
GetMatrix(StartX,StartY,Dimension)
{
Loop, %Dimension%
{
Loop, %Dimension%
{
PixelGetColor, Pix, %StartX%, %StartY%
Matrix = %Matrix%|%Pix%
StartX ++
}
StartY ++
StartX -= %Dimension%
}
StringTrimLeft, Matrix, Matrix, 1
Return %Matrix%
}
;___________________________________________
FindMatrix(ScanStartX,ScanEndX,ScanStartY,ScanEndY,Dimension,Matrix)
{
StringSplit, Pix, Matrix, |
Length := ScanEndY - ScanStartY
;loop for per line of screenY
Loop, %Length%
{
StartX = %ScanStartX%
EndX = %ScanEndX%
StartY := ScanStartY + A_Index - 1
EndY := ScanStartY + A_Index - 1
;loop for searching inside a line
Loop
{
count = 0
MatchFound = 1
;change variance and 'Fast' if not suited
PixelSearch, pX, pY, %StartX%, %StartY%, %EndX%, %EndY%, %Pix1%, 0, Fast
IfNotEqual, ERRORLEVEL, 0, Break
sX = %pX%
sY = %pY%
;loop for matching
Loop, %Dimension%
{
Loop, %Dimension%
{
Count ++
PixelGetColor, CurrPix, %pX%, %pY%
IfNotEqual, Pix%Count%, %CurrPix%
MatchFound = 0
IfEqual, MatchFound, 0, Break
pX ++
}
IfEqual, MatchFound, 0, Break
pY ++
pX -= %Dimension%
}
;match found!
IfEqual, MatchFound, 1
{
Result = %sX% %sY%
Return Result
}
StartX ++
DiffX := EndX - StartX
IfLess, DiffX, %Dimension%, Break
}
StartY ++
EndY ++
}
Return 0
}
;___________________________________________
|