Jump to content

Pixelsearch - My Brain Will Explode


Guest Pornman
 Share

Recommended Posts

Guest Pornman

hi,

im quite new with auto-it v3

ive longly studied the syntaxe and possiblilty of the pixelsearch() command

but i got a problem to make an good algorithme :whistle: let me explaine myself:

exemple: i make the evil icon move across screen ( B) ) but some other icon are moving like mad ( :angry: ) i want make an algorithm who make the difference betwin this to icon by taking red color as base.

i know it oculd look a bit weird but i want make it

if my exemple is not enough clear just tell me

tka a lot

Pornman

Link to comment
Share on other sites

  • 18 years later...

I may not be understanding your question, however, I'll offer this utility we use all the time.

Func IsColorAtPos2($x,$y,$color,$colorTolerance=0,$deltaX=0,$deltay=0,$checkTimes=1,$minimumFoundCount=1,$sleepTime=10)
    ; this function returns true if the color is found at the position specified, false if not
    ; $x                    = centroid x coordinate of the area to search
    ; $y                    = centroid y coordinate of the area to search
    ; $color                = the decimal color you wish to search for
    ; $colorTolerance       = the decimal color tolerance allowable for the $color you wish to search for.  Default: no tolerance
    ; $deltaX               = the plus and minus pixels from the $x centroid to search.  Default: no tolerance, only look at the $x centroid pixel
    ; $deltaY               = the plus and minus pixels from the $y centroid to search.  Default: no tolerance, only look at the $y centroid pixel
    ; $checkTimes           = how many times to check the area for the $color (w/ tolerance as appropriate).  Default: one time
    ; $minimumFoundCount    = minimum number of times the $color (w/ tolerance as appropriate) must be found. Default: one time
    ; $sleepTime            = the msec between checks when using $checkTime.  Default: 10 MS
    If $colorTolerance = 0 AND $deltaX=0 AND $deltaY=0 Then
        $foundCount = 0
        For $i=1 To $checkTimes
            If PixelGetColor($x,$y)=$color Then
                $foundCount = $foundCount+1
            EndIf
        Next
        If $foundCount >= $minimumFoundCount Then
            Return True
        Else
            Return False
        EndIf
    Else
        $foundCount = 0
        For $i=1 To $checkTimes
            $pos=PixelSearch($x-$deltaX,$y-$deltaY,$x+$deltaX,$y+$deltaY,$color,$colorTolerance)
            If @error Then
            Else
                $foundCount=$foundCount+1
            EndIf
            Sleep($sleepTime)
        Next
        If $foundCount >= $minimumFoundCount Then
            Return True
        Else
            Return False
        EndIf
    EndIf
EndFunc

; find out if the color at coordinate (100,100) is white
If IsColorAtPos2(100,100,16777215) Then
    ConsoleWrite("White color found"&@CRLF)
Else
    ConsoleWrite("not white"&@CRLF)
EndIf

; find out if the color at coordinate (100 +/- 50,100 +/1 20) is white with a tolerance of 100.  Must find at least 5 times within 600 ms.  Sample every 75ms
If IsColorAtPos2(100,100,16777215,100,50,20,300/75,5,75) Then
    ConsoleWrite("White found within tolerance at least 5 times"&@CRLF)
Else
    ConsoleWrite("white color not found, or not found enough times"&@CRLF)
EndIf

 

Link to comment
Share on other sites

  • Jos locked this topic
Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...