Here is my latest script: Color Selector and a simple color distance calculation.
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#Region ### START Koda GUI section ### Form=
#NoTrayIcon
$color1=""
$color2=""
_TwoColorSelection($color1,$color2)
ConsoleWrite ($color1 & " / " & $color2 & @CRLF)
Exit
Func _TwoColorSelection(ByRef $col1, ByRef $col2)
Local $upd=1, $tmp
Local $SL[6][2]
Local $ColorForm1 = GUICreate("Color Selector:", 323, 302, -1, -1)
For $x=0 to 2
$SL[$x][0] = GUICtrlCreateSlider(8+($x*46), 14, 31, 208, BitOR($GUI_SS_DEFAULT_SLIDER, $TBS_VERT))
GUICtrlSetLimit(-1, 255, 0)
$SL[$x+3][0] = GUICtrlCreateSlider(187+($x*46), 14, 31, 208, BitOR($GUI_SS_DEFAULT_SLIDER, $TBS_VERT))
GUICtrlSetLimit(-1, 255, 0)
Next
GUICtrlCreateLabel("R G B", 14, 3, 128, 15)
GUICtrlCreateLabel("R G B", 192, 3, 128, 15)
Local $BTNCOLL = GUICtrlCreateButton("@@##TEST##@@", 8, 225, 124, 30)
Local $BTNCOLR = GUICtrlCreateButton("@@##TEST##@@", 187, 224, 127, 30)
Local $InpLeftH = GUICtrlCreateInput("", 24, 260, 84, 16, 9) ;9 = Centered + Uppercase
Local $InpRightH = GUICtrlCreateInput("", 207, 260, 84, 16, 9) ;9 = Centered + Uppercase
Local $InpLeft = GUICtrlCreateInput("", 24, 279, 84, 16, 9) ;9 = Centered + Uppercase
Local $InpRight = GUICtrlCreateInput("", 207, 279, 84, 16, 9) ;9 = Centered + Uppercase
GUICtrlCreateLabel("Distance:", 135, 255, 44, 24)
Local $labelDistance = GUICtrlCreateLabel("", 134, 270, 64, 24)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
GUIDelete()
$SL=""
Return
;Case $SL[0][0], $SL[1][0], $SL[2][0], $SL[3][0], $SL[4][0], $SL[5][0] ;Probably not needed because of the loop
; $upd=1
EndSwitch
For $x=0 to 5 ;Check if the sliders have been changed with keyboard or mousewheel movement
$tmp=GuiCtrlRead($SL[$x][0],2)
if $SL[$x][1]<>$tmp then
$upd=1
$SL[$x][1]=$tmp
ExitLoop
EndIf
Next
If $upd=1 Then
Local $1R = 255 - GUICtrlRead($SL[0][0], 2), $1G = 255 - GUICtrlRead($SL[1][0], 2), $1B = 255 - GUICtrlRead($SL[2][0], 2)
Local $2R = 255 - GUICtrlRead($SL[3][0], 2), $2G = 255 - GUICtrlRead($SL[4][0], 2), $2B = 255 - GUICtrlRead($SL[5][0], 2)
Local $1RH = Hex($1R, 2), $1GH = Hex($1G, 2), $1BH = Hex($1B, 2)
Local $2RH = Hex($2R, 2), $2GH = Hex($2G, 2), $2BH = Hex($2B, 2)
$color1=$1RH & $1GH & $1BH
$color2=$2RH & $2GH & $2BH
GUICtrlSetData($InpLeftH, $color1)
GUICtrlSetData($InpRightH, $color2 )
GUICtrlSetData($InpLeft, $1R & "," & $1G & "," & $1B)
GUICtrlSetData($InpRight, $2R & "," & $2G & "," & $2B)
GUICtrlSetBkColor($BTNCOLL, "0X" & $1RH & $1GH & $1BH)
GUICtrlSetBkColor($BTNCOLR, "0X" & $2RH & $2GH & $2BH)
GUICtrlSetColor($BTNCOLR, "0X" & $1RH & $1GH & $1BH)
GUICtrlSetColor($BTNCOLL, "0X" & $2RH & $2GH & $2BH)
$CD = CalculateColorDistance(GUICtrlRead($InpLeftH), GUICtrlRead($InpRightH))
GUICtrlSetData($labelDistance, $CD & " 0x" & Hex($CD, 4))
$upd=0
EndIf
WEnd
EndFunc ;==>_ColorSelection
Func CalculateColorDistance($RGB1 = "000000", $RGB2 = "FFFFFF")
;Format RGB as hex string
If IsString($RGB1) = 1 Then
$RGB1 = StringReplace($RGB1, "0x", "")
Else
$RGB1=Hex($RGB1,6)
EndIf
If IsString($RGB2) = 1 Then
$RGB2 = StringReplace($RGB2, "0x", "")
Else
$RGB2=Hex($RGB2,6)
EndIf
If StringLen($RGB1) < 6 Then Return -1
If StringLen($RGB2) < 6 Then Return -1
If StringLen($RGB1) > 6 Then $RGB1 = StringRight($RGB1, 6) ;Assuming the ARGB format
If StringLen($RGB2) > 6 Then $RGB2 = StringRight($RGB2, 6) ;Assuming the ARGB format
Local $1R = Int("0x" & StringMid($RGB1, 1, 2)), $1G = Int("0x" & StringMid($RGB1, 3, 2)), $1B = Int("0x" & StringMid($RGB1, 5, 2))
Local $2R = Int("0x" & StringMid($RGB2, 1, 2)), $2G = Int("0x" & StringMid($RGB2, 3, 2)), $2B = Int("0x" & StringMid($RGB2, 5, 2))
;$DR = $1R - $2R ;$DG = $1G - $2G ;$DB = $1B - $2B
Return Int(Abs($1R - $2R) + Abs($1G - $2G) + Abs($1B - $2B))
EndFunc ;==>CalculateColorDistance
The distance calculations is very basic.
Provide 2 color values in RGB format (e.g. "FF10FF" or 0x12FCD4).
Each pair of R,G and B values is first substracted then the distance is calculated by adding them.
As an extra feature: The color values are calculated even when the slider is changed by the mouse wheel (or arrow keys).