Jump to content

PixelGetColor Variations?


 Share

Recommended Posts

I know that you can apply a color variation to PixelSearch, but can you apply a color variation to PixelGetColor?,

Basically I have this and need to setup a color variation somewhere in it.

Func _Start()
$Position = MouseGetPos()
    $coord = PixelGetColor ($Position[0], $Position[1])
        If $coord = $Color Then
            Do nothing
Endif
WEnd
EndFunc

Func _Color()
    $MOUSEGET = MouseGetPos()
        $Color = PixelGetColor ($MOUSEGET[0], $MOUSEGET[1])
            TrayTip("Chosen HEX Color", Hex($Color, 6), 1)
EndFunc
Link to comment
Share on other sites

Your statement is confusing.

PixelSearch uses variation so that it responds to a pixel whose color is within a certain degree of variation from the target color.

PixelGetColor just returns the color value of the target pixel. How the hell is color variation involved in that operation?

Link to comment
Share on other sites

I understand, I might have to use PixelSearch instead. I misunderstood the PixelGetColor operation. If I use PixelSearch, How can I make it search on the very center of my screen? I tried using @DesktopWidth /2, @DesktopHeight /2 but it wants four values, If I try to use four values, it doesn't work at all, but gives no errors.

Func _Start()
$Position = MouseGetPos()
    $coord = PixelSearch (@DesktopWidth /2, @DesktopHeight /2, COORD?, COORD?, 50)
        If $coord = $Color Then
            Do nothing
Endif
WEnd
EndFunc

What do COORD? and COORD? have to be to make it search the center of my screen?

Link to comment
Share on other sites

This creates a regular expression compare pattern to test a color against.

HotKeySet("{ESC}", "Terminate")
HotKeySet("+!d", "_Color") ; Shift-Alt-d

Global $iColRnge = 0x808080
Global $iRnge = 100

While 1
    Sleep(100)
WEnd


Func _Color()
    Local $position = MouseGetPos()
    Local $iColor = PixelGetColor($position[0], $position[1])
    If _ColorMatch($iColor, $iColRnge, $iRnge) Then
        TrayTip("Chosen RGB HEX Color", "0x" & Hex($iColor, 6) & " = 0x" & Hex($iColRnge, 6) & " " & Chr(177) & $iRnge, 1)
    Else
        TrayTip("Chosen RGB HEX Color", "0x" & Hex($iColor, 6) & " <> 0x" & Hex($iColRnge, 6) & " " & Chr(177) & $iRnge, 1)
    EndIf
EndFunc ;==>_Color

;======================== _ColorMatch ===========================
; Description - Checks if a 24bit color matches a specified color plus or minus a shade varation.
; Parameters
;   $iColor         - A 'RGB' or 'BGR' color to test.
;   $iColPlusShade  - A 'RGB' or 'BGR' color to which a shade variation will be added, to test $iColor against.
;   $ShadeVariation - An integer added to and substracted from each color channel of the color, $iColPlusShade.
; Returns 1 (matched) or 0 (no match)
;
Func _ColorMatch($iColor, $iColPlusShade, $ShadeVariation)
    $aColor = StringRegExp(Hex($iColPlusShade, 6), "(.{2})", 3)
    $iColSrch = __StringRERange("0x" & $aColor[0], $ShadeVariation) & __StringRERange("0x" & $aColor[1], $ShadeVariation) & _
            __StringRERange("0x" & $aColor[2], $ShadeVariation) ; & __StringRERange("0x" & $aviAlpha, $ShadeVariation)
    ;ConsoleWrite("$iColSrch " & $iColSrch & @CRLF)
    Return StringRegExp(Hex($iColor, 6), $iColSrch)
EndFunc ;==>_ColorMatch

;Internal function
Func __StringRERange($iColSrch, $ShadeVariation)
    Local $str = "(", $iColSrchMin, $iColSrchMax
    $iColSrchMin = "0x" & Hex((Dec(Hex($iColSrch)) - $ShadeVariation) * ((Dec(Hex($iColSrch)) - $ShadeVariation) > 0), 2)
    $iColSrchMax = "0x" & Hex((Dec(Hex($iColSrch)) + $ShadeVariation) * ((Dec(Hex($iColSrch)) + $ShadeVariation) < 255) + 255, 2)
    For $n = $iColSrchMin To $iColSrchMax + 1
        $str &= Hex($n, 2) & "|"
    Next
    $str = StringTrimRight($str, 1) & ")"
    Return $str
EndFunc ;==>__StringRERange
;===================> End of _ColorMatch ===========================

Func Terminate()
    Exit 0
EndFunc ;==>Terminate
Link to comment
Share on other sites

Omikron48, Your thread helped for sure, Thank you. But Im still confused as to where the center of my screen is. I wanted to us something like this but dont know what value to make the question marks.

$SquarePosition = PixelSearch(@DesktopWidth /2+?, @DesktopHeight /2+?, @DesktopWidth /2+?, @DesktopHeight /2+?,$color,15)
                                If IsArray($SquarePosition) Then
                                    MouseClick("left")

I know the x y is 840,525, but I need four variables.

Link to comment
Share on other sites

Well, technically, there is no center pixel on your screen because your screen size always has even valued dimensions.

If I'm to guess the parameters... Maybe:

PixelSearch(@DesktopWidth /2, @DesktopHeight /2, @DesktopWidth /2+1, @DesktopHeight /2+1,$color,15)

This will search the 2x2 pixel square located at the center of your screen.

EDIT: If the pixel location to be checked, (840,525), is constant, then all you need to check it is just plug in the coordinates in PixelSearch.

PixelSearch(840, 525, 840, 525,$color,15)
Edited by omikron48
Link to comment
Share on other sites

Before you posted this I created an alternate solution that would be universal regardless of resolution

_MouseTrap (@DesktopWidth /2, @DesktopHeight /2)
$MOUSEGET = MouseGetPos()
    $SquarePosition = PixelSearch($MOUSEGET[0]+4, $MOUSEGET[1]+4, $MOUSEGET[0]+4, $MOUSEGET[1]+4,$color,15)
        If IsArray($SquarePosition) Then
            MouseClick("left")

The full script is actually quite impressive, but according to the rules of the boards here I cannot post it :mellow: But after 3 days of searching these boards I could not find a similar script that would work in D3D....

But it's very light weight, and because it's only searching a 4x4 area, it doesn't slow me down at all, and I have no sleep function in the script at all, making it very responsive.

Link to comment
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
 Share

  • Recently Browsing   0 members

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