Jump to content
Sign in to follow this  
Guest Goat

Noob Q : Pixel Group?

Recommended Posts

Guest Goat

i was wondering how to make auto it look for a group of pixels of a certain colour? or is it not possible?

Share this post


Link to post
Share on other sites

i was wondering how to make auto it look for a group of pixels of a certain colour?  or is it not possible?

<{POST_SNAPBACK}>

Hello look on the Autoit3 help files or use the search func on his forums!

Ok I Post you This exampel of Pixelsearch to learn from it) :idiot:

HotKeySet("{esc}", "test")
Global $test

While 1
   If $Test Then
      Sleep(2000)
      MouseClick( "left", 955, 657, 2, 1)
      $a = _LoadPixelRectFromFile( "testes.txt")
      $b = _FindPixelRect(354, 188, 460, 629, $a)
      If Not @error Then
         Call("Play")
         ContinueLoop
      Else
         Sleep(1000)
         MouseMove(615, 687, 1)
         Sleep(1000)
         MouseClick( "left", 615, 687, 1, 1)
         ContinueLoop
      EndIf
   EndIf
   
WEnd

Func Test()
   $test= Not $Test
EndFunc  ;==>test

Func Play()
   MouseMove($b[0], $b[1])
   Sleep(1000)
   MouseClick( "left")
   Sleep(3000)
   Send("ggggg")
   Sleep(500)
   MouseClick( "left")
   Sleep(5000)
  EndFunc  ;==>Play

Func _FindPixelRect($_NL, $_NT, $_NR, $_NB, ByRef $_APIXRECT)
   If Not IsArray($_APIXRECT) Or Not UBound($_APIXRECT, 2) Then
      SetError(1)
      Return 0
   EndIf
   
   If ($_NL + UBound($_APIXRECT, 2) > $_NR) Or ($_NT + UBound($_APIXRECT) > $_NB) Then
      SetError(2)
      Return 0
   EndIf
   
   $_NR = $_NR - UBound($_APIXRECT, 2) + 1
   $_NB = $_NB - UBound($_APIXRECT) + 1
   $_NLIMITX = UBound($_APIXRECT)
   $_NLIMITY = UBound($_APIXRECT, 2)
   
   $_ACOORD = PixelSearch($_NL, $_NT, $_NR, $_NB, $_APIXRECT[0][0])
   While Not @error
      For $_NY = 1 To $_NLIMITY
         For $_NX = 1 To $_NLIMITX
            If $_APIXRECT[$_NY - 1][$_NX - 1] <> PixelGetColor($_ACOORD[0] + $_NX - 1, $_ACOORD[1] + $_NY - 1) Then
               SetError(1)
               ExitLoop 2
            EndIf
         Next
      Next
      If Not @error Then
         Return $_ACOORD
      Else
         $_ATEMP = PixelSearch($_ACOORD[0] + 1, $_ACOORD[1], $_NR, $_ACOORD[1], $_APIXRECT[0][0])
         If @error Then
            $_NT = $_ACOORD[1] + 1
            If $_NT > $_NB Then
               SetError(1)
               Return 0
            EndIf
            $_ACOORD = PixelSearch($_NL, $_NT, $_NR, $_NB, $_APIXRECT[0][0])
         Else
            $_ACOORD = $_ATEMP
         EndIf
      EndIf
   WEnd
   SetError(1)
   Return 0
EndFunc  ;==>_FindPixelRect


Func _LoadPixelRect($_NL, $_NT, $_NR, $_NB)
   If ($_NL > $_NR Or $_NT > $_NB) Then
      SetError(1)
      Return 0
   EndIf
   
   Dim $_APIXRECT[$_NB - $_NT + 1][$_NR - $_NL + 1]
   
   For $_NY = $_NT To $_NB
      For $_NX = $_NL To $_NR
         $_APIXRECT[$_NY - $_NT][$_NX - $_NL] = PixelGetColor($_NX, $_NY)
      Next
   Next
   
   Return $_APIXRECT
EndFunc  ;==>_LoadPixelRect


Func _LoadPixelRectFromFile($_SZBUFFER)
   If Not FileExists($_SZBUFFER) Then
      SetError(1)
      Return 0
   EndIf
   
   $_SZBUFFER = StringStripCR(FileRead($_SZBUFFER, FileGetSize($_SZBUFFER)))
   If StringRight($_SZBUFFER, 1) == @LF Then $_SZBUFFER = StringTrimRight($_SZBUFFER, 1)
   $_SZBUFFER = StringSplit($_SZBUFFER, @LF)
   $_SZLINE = StringSplit($_SZBUFFER[1], ",")
   
   $_NLIMITX = $_SZLINE[0]
   $_NLIMITY = $_SZBUFFER[0]
   
   Dim $_APIXRECT[$_NLIMITY][$_NLIMITX]
   
   For $_NY = 1 To $_NLIMITY
      $_SZLINE = StringSplit($_SZBUFFER[$_NY], ",")
      If $_SZLINE[0] <> $_NLIMITX Then
         SetError(1)
         Return 0
      EndIf
      For $_NX = 1 To $_NLIMITX
         $_APIXRECT[$_NY - 1][$_NX - 1] = Number($_SZLINE[$_NX])
      Next
   Next
   
   Return $_APIXRECT
EndFunc  ;==>_LoadPixelRectFromFile


Func _SavePixelRect(ByRef $_ARECT, $_SZFILE)
   Dim $_SZBUFFER = ""
   
   If Not IsArray($_ARECT) Or Not UBound($_ARECT, 2) Then
      SetError(1)
      Return 0
   EndIf
   
   $_LIMITY = UBound($_ARECT)
   $_LIMITX = UBound($_ARECT, 2)
   
   For $_NY = 0 To $_LIMITY - 1
      For $_NX = 0 To $_LIMITX - 1
         $_SZBUFFER = $_SZBUFFER & $_ARECT[$_NY][$_NX] & ","
      Next
      $_SZBUFFER = StringTrimRight($_SZBUFFER, 1) & @CRLF
   Next
   
   $_SZBUFFER = StringTrimRight($_SZBUFFER, 2)
   
   FileDelete($_SZFILE)
   FileWrite($_SZFILE, $_SZBUFFER)
   Return 1
EndFunc  ;==>_SavePixelRect
Edited by DirtyBanditos

Share this post


Link to post
Share on other sites

I couldn't even learn from that... I'd have to study the entire thing.

I suggest you just look at the help file for pixelsearch :idiot:


"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.

Share this post


Link to post
Share on other sites

DiryBanditos... that looks nice but since he is new, maye just a little simple script will suit his needs :idiot:

Straight from helpfile.. :D

;Function:
PixelSearch ( left, top, right, bottom, color [, shade-variation] [, step]] )






; Find a pure red pixel in the range 0,0-20,300
$coord = PixelSearch( 0, 0, 20, 300, 0xFF0000 )
If Not @error Then
    MsgBox(0, "X and Y are:", $coord[0] & "," & $coord[1])
EndIf


; Find a pure red pixel or a red pixel within 10 shades variations of pure red
$coord = PixelSearch( 0, 0, 20, 300, 0xFF0000, 10 )
If Not @error Then
    MsgBox(0, "X and Y are:", $coord[0] & "," & $coord[1])
EndIf

i recomend you go to the help file and go to the index and search "PixelSearch"...


FootbaG

Share this post


Link to post
Share on other sites

DiryBanditos... that looks nice but since he is new, maye just a little simple script will suit his needs :D

Straight from helpfile.. :lol:

;Function:
PixelSearch ( left, top, right, bottom, color [, shade-variation] [, step]] )
; Find a pure red pixel in the range 0,0-20,300
$coord = PixelSearch( 0, 0, 20, 300, 0xFF0000 )
If Not @error Then
    MsgBox(0, "X and Y are:", $coord[0] & "," & $coord[1])
EndIf
; Find a pure red pixel or a red pixel within 10 shades variations of pure red
$coord = PixelSearch( 0, 0, 20, 300, 0xFF0000, 10 )
If Not @error Then
    MsgBox(0, "X and Y are:", $coord[0] & "," & $coord[1])
EndIf

i recomend you go to the help file and go to the index and search "PixelSearch"...

<{POST_SNAPBACK}>

;) Sorry Layer :D you have right! :idiot: Edited by DirtyBanditos

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...