Jump to content

If you want to play with colors ...


grham
 Share

Recommended Posts

Imagine you have a color (RGB) and you want to know his

hue, saturation and brightness and get it's complementary color,

set the brightness or saturation for the same hue or other hues

with the same B and S ....

maybe it's not much usefull for the major part of you, but just for playing

a little:

#include<Array.au3>
#include<Color.au3>
#include<GUIConstantsEx.au3>
#include <GuiSlider.au3>

Global $Sel_Hue, $Sel_Saturation, $Sel_Brightness
Const $WS_EX_COMPOSITED = 0x2000000

$GUI = GUICreate("", 440, 260, -1, -1, -1, $WS_EX_COMPOSITED)
$gra1 = GUICtrlCreateGraphic(50, 20, 362, 20, $SS_SUNKEN)
$gra2 = GUICtrlCreateGraphic(50, 70, 362, 20, $SS_SUNKEN)
$gra3 = GUICtrlCreateGraphic(50, 120, 362, 20, $SS_SUNKEN)

GUISetBkColor(0xc0c0c0)
GUISetState()
GUISetState(@SW_LOCK)

$Color = 0x4383C0
$Start_Hue = _Color_GetHue($Color)
$Start_Saturation = _Color_GetSaturation($Color)
$Start_Brightness = _Color_GetBrightness($Color)
$Start_Complementary = _Color_FindComplementary($Color)

ConsoleWrite("Color: 0x" & Hex($Color, 6) & @CRLF)
ConsoleWrite("Saturation: " & $Start_Saturation & " %" & @CRLF)
ConsoleWrite("Brightness: " & $Start_Brightness & " %" & @CRLF)
ConsoleWrite("Hue: " & $Start_Hue & " º" & @CRLF)
ConsoleWrite("Complementary color: " & $Start_Complementary & @CRLF & @CRLF)

GUICtrlCreateLabel("H:", 10, 23, 40, 15)
GUICtrlCreateLabel("S:", 10, 73, 40, 15)
GUICtrlCreateLabel("B:", 10, 123, 40, 15)

For $x = 0 To 360 Step 2
    $hue = _Color_SetHue($Color, $x)
    ConsoleWrite("Hue: " & $x & " º" & $hue & @CRLF)
    GUICtrlSetGraphic($gra1, $GUI_GR_COLOR, $hue, $hue)
    GUICtrlSetGraphic($gra1, $GUI_GR_RECT, $x, 0, 2, 20)
Next
GUICtrlSetGraphic($gra1, $GUI_GR_REFRESH)

ConsoleWrite("  Saturation:  Brightness:" & @CRLF)
$Pass = 3.6
$Step = 0
$Diff = 0
For $x = 0 To 100
    $sat = _Color_SetSaturation($Color, $x)
    $brigth = _Color_SetBrightness($Color, $x)
    ConsoleWrite($x & " % " & $sat & "   " & $brigth & @CRLF)
    GUICtrlSetGraphic($gra2, $GUI_GR_COLOR, $sat, $sat)
    GUICtrlSetGraphic($gra3, $GUI_GR_COLOR, $brigth, $brigth)
    GUICtrlSetGraphic($gra2, $GUI_GR_RECT, Round($Diff), 0, 4, 20)
    GUICtrlSetGraphic($gra3, $GUI_GR_RECT, Round($Diff), 0, 4, 20)
    $Diff += $Pass
    If $x = 1 Then $Diff = 3
Next
GUICtrlSetGraphic($gra2, $GUI_GR_REFRESH)
GUICtrlSetGraphic($gra3, $GUI_GR_REFRESH)

$Slider_H = _GUICtrlSlider_Create ($GUI, 45, 42, 372, 18, BitOR($TBS_TOOLTIPS, $TBS_AUTOTICKS, $TBS_ENABLESELRANGE, $TBS_TOP))
_GUICtrlSlider_SetRange($Slider_H, 0, 360)
_GUICtrlSlider_SetPos($Slider_H, $Start_Hue)
$Slider_S = _GUICtrlSlider_Create ($GUI, 45, 92, 372, 18, BitOR($TBS_TOOLTIPS, $TBS_AUTOTICKS, $TBS_ENABLESELRANGE, $TBS_TOP))
_GUICtrlSlider_SetRange($Slider_S, 0, 100)
_GUICtrlSlider_SetPos($Slider_S, $Start_Saturation)
$Slider_B = _GUICtrlSlider_Create ($GUI, 45, 142, 372, 18, BitOR($TBS_TOOLTIPS, $TBS_AUTOTICKS, $TBS_ENABLESELRANGE, $TBS_TOP))
_GUICtrlSlider_SetRange($Slider_B, 0, 100)
_GUICtrlSlider_SetPos($Slider_B, $Start_Brightness)

$Original_Label = GUICtrlCreateLabel("H: " & $Start_Hue & @CRLF & "S: " & $Start_Saturation & @CRLF & "B: " & $Start_Brightness, 50, 185, 50, 60)  
GUICtrlCreateLabel("==>", 170, 200, 25, 15)  
$New_Label = GUICtrlCreateLabel("H: " & $Start_Hue & @CRLF & "S: " & $Start_Saturation & @CRLF & "B: " & $Start_Brightness, 280, 185, 50, 60)  

$Original = GUICtrlCreateGraphic(100, 190, 60, 35, $SS_SUNKEN)
GUICtrlSetGraphic($Original, $GUI_GR_COLOR, $Color, $Color)
GUICtrlSetGraphic($Original, $GUI_GR_RECT, 0, 0, 60, 35)
GUICtrlSetGraphic($Original, $GUI_GR_REFRESH)
GUICtrlCreateLabel("0x" & Hex($Color, 6), 103, 227, 54, 15)

$New = GUICtrlCreateGraphic(200, 190, 60, 35, $SS_SUNKEN)
GUICtrlSetGraphic($New, $GUI_GR_COLOR, $Color, $Color)
GUICtrlSetGraphic($New, $GUI_GR_RECT, 0, 0, 60, 35)
GUICtrlSetGraphic($New, $GUI_GR_REFRESH)
$New_Input = GUICtrlCreateInput("0x" & Hex($Color, 6), 203, 227, 54, 15, "", $WS_EX_STATICEDGE)
GUICtrlSetBkColor(-1, 0xc0c0c0)

$Complementary = GUICtrlCreateButton("complementary" & @CRLF & "color?", 326, 190, 82, 30, $BS_MULTILINE)
GUICtrlSetBkColor($Complementary, 0xc0c0c0)

GUISetState(@SW_UNLOCK)

While 1
    $msg = GUIGetMsg()
    If $msg = -3 Then Exit
    If $msg = $Complementary Then _GUICtrlSlider_SetPos($Slider_H, Mod(($Start_Hue+180), 360))
    $Read_H = _GUICtrlSlider_GetPos($Slider_H)
    $Read_S = _GUICtrlSlider_GetPos($Slider_S)
    $Read_B = _GUICtrlSlider_GetPos($Slider_B)
    If $Read_H <> $Sel_Hue Then
        $Sel_Hue = $Read_H
        $Sel_Color = _Color_SetHue($Color, $Sel_Hue)
        GUICtrlSetGraphic($New, $GUI_GR_COLOR, $Sel_Color, $Sel_Color)
        GUICtrlSetGraphic($New, $GUI_GR_RECT, 0, 0, 60, 35)
        GUICtrlSetGraphic($New, $GUI_GR_REFRESH)
        If _GUICtrlSlider_GetPos($Slider_S) <> $Start_Saturation Then _GUICtrlSlider_SetPos($Slider_S, $Start_Saturation)
        If _GUICtrlSlider_GetPos($Slider_B) <> $Start_Brightness Then _GUICtrlSlider_SetPos($Slider_B, $Start_Brightness)
        GUICtrlSetData($New_Label, "H: " & $Read_H & @CRLF & "S: " & $Start_Saturation & @CRLF & "B: " & $Start_Brightness)
        GUICtrlSetData($New_Input, $Sel_Color)
    ElseIf $Read_S <> $Sel_Saturation Then
        $Sel_Saturation = $Read_S
        $Sel_Color = _Color_SetSaturation($Color, $Sel_Saturation)
        GUICtrlSetGraphic($New, $GUI_GR_COLOR, $Sel_Color, $Sel_Color)
        GUICtrlSetGraphic($New, $GUI_GR_RECT, 0, 0, 60, 35)
        GUICtrlSetGraphic($New, $GUI_GR_REFRESH)
        If _GUICtrlSlider_GetPos($Slider_H) <> $Start_Hue Then _GUICtrlSlider_SetPos($Slider_H, $Start_Hue)
        If _GUICtrlSlider_GetPos($Slider_B) <> $Start_Brightness Then _GUICtrlSlider_SetPos($Slider_B, $Start_Brightness)
        GUICtrlSetData($New_Label, "H: " & $Start_Hue & @CRLF & "S: " & $Read_S & @CRLF & "B: " & $Start_Brightness)
        GUICtrlSetData($New_Input, $Sel_Color)
    ElseIf $Read_B <> $Sel_Brightness Then
        $Sel_Brightness = $Read_B
        $Sel_Color = _Color_SetBrightness($Color, $Sel_Brightness)
        GUICtrlSetGraphic($New, $GUI_GR_COLOR, $Sel_Color, $Sel_Color)
        GUICtrlSetGraphic($New, $GUI_GR_RECT, 0, 0, 60, 35)
        GUICtrlSetGraphic($New, $GUI_GR_REFRESH)
        If _GUICtrlSlider_GetPos($Slider_H) <> $Start_Hue Then _GUICtrlSlider_SetPos($Slider_H, $Start_Hue)
        If _GUICtrlSlider_GetPos($Slider_S) <> $Start_Saturation Then _GUICtrlSlider_SetPos($Slider_S, $Start_Saturation)
        GUICtrlSetData($New_Label, "H: " & $Start_Hue & @CRLF & "S: " & $Start_Saturation & @CRLF & "B: " & $Read_B)
        GUICtrlSetData($New_Input, $Sel_Color)
    EndIf   
    Sleep(10)
WEnd    

;==============================================================================================

Func _Color_SetSaturation($iColor, $nPercent)
    Local $aColorArray[4]
    $nPercent = 1 - ($nPercent / 100)

    $aColorArray[1] = _ColorGetRed($iColor)
    $aColorArray[2] = _ColorGetGreen($iColor)
    $aColorArray[3] = _ColorGetBlue($iColor)

    If $aColorArray[1] = $aColorArray[2] And $aColorArray[2] = $aColorArray[3] Then Return -1

    $IndexMax = _ArrayMaxIndex($aColorArray, 1, 1)
    $IndexMin = _ArrayMinIndex($aColorArray, 1, 1)
    $IndexMid = 6 - ($IndexMax + $IndexMin)

    $aColorArray[$IndexMid] = ($aColorArray[$IndexMax] * ($aColorArray[$IndexMid] - $aColorArray[$IndexMin])) / ($aColorArray[$IndexMax] - $aColorArray[$IndexMin])
    $aColorArray[$IndexMid] = Round($aColorArray[$IndexMid] + ($aColorArray[$IndexMax] - $aColorArray[$IndexMid]) * $nPercent, 0)

    $aColorArray[$IndexMin] = Round($aColorArray[$IndexMax] * $nPercent, 0)
    Return 0 & "x" & Hex($aColorArray[1], 2) & Hex($aColorArray[2], 2) & Hex($aColorArray[3], 2)
EndFunc;==>_Color_SetSaturation

Func _Color_GetSaturation($iColor)
    Local $aColorArray[4]

    $aColorArray[1] = _ColorGetRed($iColor)
    $aColorArray[2] = _ColorGetGreen($iColor)
    $aColorArray[3] = _ColorGetBlue($iColor)

    $IndexMax = _ArrayMaxIndex($aColorArray, 1, 1)
    $IndexMin = _ArrayMinIndex($aColorArray, 1, 1)
    $IndexMid = 6 - ($IndexMax + $IndexMin)
    Return Round((1 - $aColorArray[$IndexMin] / $aColorArray[$IndexMax]) * 100, 0)
EndFunc;==>_Color_GetSaturation

Func _Color_SetBrightness($iColor, $nPercent)
    Local $aColorArray[4]
    $nPercent = $nPercent / 100

    $aColorArray[1] = _ColorGetRed($iColor)
    $aColorArray[2] = _ColorGetGreen($iColor)
    $aColorArray[3] = _ColorGetBlue($iColor)

    $IndexMax = _ArrayMaxIndex($aColorArray, 1, 1)
    $ActBrightness = $aColorArray[$IndexMax] / 255
    For $i = 1 To 3
        $aColorArray[$i] = Round($aColorArray[$i] * $nPercent / $ActBrightness, 0)
    Next
    Return 0 & "x" & Hex($aColorArray[1], 2) & Hex($aColorArray[2], 2) & Hex($aColorArray[3], 2)
EndFunc;==>_Color_SetBrightness

Func _Color_GetBrightness($iColor)
    Local $aColorArray[4]

    $aColorArray[1] = _ColorGetRed($iColor)
    $aColorArray[2] = _ColorGetGreen($iColor)
    $aColorArray[3] = _ColorGetBlue($iColor)

    $IndexMax = _ArrayMaxIndex($aColorArray, 1, 1)
    Return Round(($aColorArray[$IndexMax] / 255) * 100, 0)
EndFunc;==>_Color_GetBrightness

Func _Color_SetHue($iColor, $iHue)
    Local $aColorArray[4]

    $aColorArray[1] = _ColorGetRed($iColor)
    $aColorArray[2] = _ColorGetGreen($iColor)
    $aColorArray[3] = _ColorGetBlue($iColor)

    $iMax = _ArrayMax($aColorArray, 1, 1)
    $iMin = _ArrayMin($aColorArray, 1, 1)

    If $iHue >= 61 And $iHue <= 180 Then
        $IndexMax = 2
        If $iHue < 120 Then
            $IndexMin = 3
            $iMid = (($iMax - $iMin) * (120 - $iHue)) / 60 + $iMin
        Else
            $IndexMin = 1
            $iMid = (($iMax - $iMin) * ($iHue - 120)) / 60 + $iMin
        EndIf
    ElseIf $iHue >= 181 And $iHue <= 299 Then
        $IndexMax = 3
        If $iHue <= 240 Then
            $IndexMin = 1
            $iMid = (($iMax - $iMin) * (240 - $iHue)) / 60 + $iMin
        Else
            $IndexMin = 2
            $iMid = (($iMax - $iMin) * ($iHue - 240)) / 60 + $iMin
        EndIf
    ElseIf $iHue >= 300 Or $iHue <= 60 Then
        $IndexMax = 1
        If $iHue <= 60 Then
            $IndexMin = 3
            $iMid = (($iMax - $iMin) * ($iHue)) / 60 + $iMin
        Else
            $IndexMin = 2
            $iMid = (($iMax - $iMin) * (360 - $iHue)) / 60 + $iMin
        EndIf
    EndIf
    $IndexMid = 6 - ($IndexMin + $IndexMax)
    $aColorArray[$IndexMin] = $iMin
    $aColorArray[$IndexMax] = $iMax
    $aColorArray[$IndexMid] = $iMid
    Return 0 & "x" & Hex($aColorArray[1], 2) & Hex($aColorArray[2], 2) & Hex($aColorArray[3], 2)
EndFunc;==>_Color_SetHue

Func _Color_GetHue($iColor)
    Local $aColorArray[4], $Hue

    $aColorArray[1] = _ColorGetRed($iColor)
    $aColorArray[2] = _ColorGetGreen($iColor)
    $aColorArray[3] = _ColorGetBlue($iColor)

    $IndexMax = _ArrayMaxIndex($aColorArray, 1, 1)
    $IndexMin = _ArrayMinIndex($aColorArray, 1, 1)
    $IndexMid = 6 - ($IndexMax + $IndexMin)
    $Lambda = ($aColorArray[$IndexMid] - $aColorArray[$IndexMin]) * 60 / ($aColorArray[$IndexMax] - $aColorArray[$IndexMin])

    Switch $IndexMax
        Case 1
            Switch $IndexMin
                Case 2
                    $Hue = 360 - $Lambda
                Case 3
                    $Hue = $Lambda
            EndSwitch
        Case 2
            Switch $IndexMin
                Case 1
                    $Hue = 120 + $Lambda
                Case 3
                    $Hue = 120 - $Lambda
            EndSwitch
        Case 3
            Switch $IndexMin
                Case 1
                    $Hue = 240 - $Lambda
                Case 2
                    $Hue = 240 + $Lambda
            EndSwitch
    EndSwitch
    Return Mod(Round($Hue, 0), 360)
EndFunc;==>_Color_GetHue

Func _Color_FindComplementary($iColor)
    Local $iHue = Mod(_Color_GetHue($iColor) + 180, 360)
    Return _Color_SetHue($iColor, $iHue)
EndFunc;==>_Color_FindComplementary

:)

Edited by grham
Link to comment
Share on other sites

Hello

Nice work, man!

Here is an example with a GUI. There you will see better, what happen :)

#include<Array.au3>
#include<Color.au3>
#include<GUIConstantsEx.au3>


GUICreate("",360,350)
$gra = GUICtrlCreateGraphic(0,0,360,20)
GUISetState()
$Color = 0xFFff00
GUISetBkColor($Color)
ConsoleWrite("Color: 0x" & Hex($Color, 6) & @CRLF)
ConsoleWrite("Saturation: " & _Color_GetSaturation($Color) & " %" & @CRLF)
ConsoleWrite("Brightness: " & _Color_GetBrightness($Color) & " %" & @CRLF)
ConsoleWrite("Hue: " & _Color_GetHue($Color) & " º" & @CRLF)
Sleep(1000)
ConsoleWrite("Complementary color: " & _Color_FindComplementary($Color) & @CRLF & @CRLF)
$i = 0
While $i < 2
    $i += 1
    GUISetBkColor(_Color_FindComplementary($Color))
    Sleep(500)
    GUISetBkColor($Color)
    Sleep(500)
WEnd
GUISetBkColor(0)
For $x = 0 To 360 Step 2
    $hue = _Color_SetHue($Color, $x)
    ConsoleWrite("Hue: " & $x & " º" & $hue & @CRLF)
;~  GUISetBkColor($hue)
    GUICtrlSetGraphic($gra,$GUI_GR_COLOR,$hue,$hue)
    GUICtrlSetGraphic($gra,$GUI_GR_RECT,$x,0,2,20)
    GUICtrlSetGraphic($gra,$GUI_GR_REFRESH)
    Sleep(30)

Next
Sleep(500)
GUISetBkColor($Color)
GUICtrlDelete($gra)
$gra = GUICtrlCreateGraphic(0,0,350,20)
$gra2 = GUICtrlCreateGraphic(0,20,350,20)


ConsoleWrite("    Saturation:  Brightness:" & @CRLF)
For $x = 0 To 100
    $sat = _Color_SetSaturation($Color, $x)
    $brigth = _Color_SetBrightness($Color, $x)
    ConsoleWrite($x & " % " & $sat & "     " & $brigth & @CRLF)
    GUICtrlSetGraphic($gra,$GUI_GR_COLOR,$sat,$sat)
    GUICtrlSetGraphic($gra2,$GUI_GR_COLOR,$brigth,$brigth)
    GUICtrlSetGraphic($gra,$GUI_GR_RECT,350*$x/100,0,Ceiling (350/100),20) 
    GUICtrlSetGraphic($gra2,$GUI_GR_RECT,350*$x/100,0,Ceiling( 350/100),20)
    GUICtrlSetGraphic($gra,$GUI_GR_REFRESH)
    GUICtrlSetGraphic($gra2,$GUI_GR_REFRESH)
    Sleep(30)
Next

Func _Color_SetSaturation($iColor, $nPercent)
    Local $aColorArray[4]
    $nPercent = 1 - ($nPercent / 100)

    $aColorArray[1] = _ColorGetRed($iColor)
    $aColorArray[2] = _ColorGetGreen($iColor)
    $aColorArray[3] = _ColorGetBlue($iColor)

    If $aColorArray[1] = $aColorArray[2] And $aColorArray[2] = $aColorArray[3] Then Return -1

    $IndexMax = _ArrayMaxIndex($aColorArray, 1, 1)
    $IndexMin = _ArrayMinIndex($aColorArray, 1, 1)
    $IndexMid = 6 - ($IndexMax + $IndexMin)

    $aColorArray[$IndexMid] = ($aColorArray[$IndexMax] * ($aColorArray[$IndexMid] - $aColorArray[$IndexMin])) / ($aColorArray[$IndexMax] - $aColorArray[$IndexMin])
    $aColorArray[$IndexMid] = Round($aColorArray[$IndexMid] + ($aColorArray[$IndexMax] - $aColorArray[$IndexMid]) * $nPercent, 0)

    $aColorArray[$IndexMin] = Round($aColorArray[$IndexMax] * $nPercent, 0)
    Return 0 & "x" & Hex($aColorArray[1], 2) & Hex($aColorArray[2], 2) & Hex($aColorArray[3], 2)
EndFunc   ;==>_Color_SetSaturation

Func _Color_GetSaturation($iColor)
    Local $aColorArray[4]

    $aColorArray[1] = _ColorGetRed($iColor)
    $aColorArray[2] = _ColorGetGreen($iColor)
    $aColorArray[3] = _ColorGetBlue($iColor)

    $IndexMax = _ArrayMaxIndex($aColorArray, 1, 1)
    $IndexMin = _ArrayMinIndex($aColorArray, 1, 1)
    $IndexMid = 6 - ($IndexMax + $IndexMin)
    Return Round((1 - $aColorArray[$IndexMin] / $aColorArray[$IndexMax]) * 100, 0)
EndFunc   ;==>_Color_GetSaturation

Func _Color_SetBrightness($iColor, $nPercent)
    Local $aColorArray[4]
    $nPercent = $nPercent / 100

    $aColorArray[1] = _ColorGetRed($iColor)
    $aColorArray[2] = _ColorGetGreen($iColor)
    $aColorArray[3] = _ColorGetBlue($iColor)

    $IndexMax = _ArrayMaxIndex($aColorArray, 1, 1)
    $ActBrightness = $aColorArray[$IndexMax] / 255
    For $i = 1 To 3
        $aColorArray[$i] = Round($aColorArray[$i] * $nPercent / $ActBrightness, 0)
    Next
    Return 0 & "x" & Hex($aColorArray[1], 2) & Hex($aColorArray[2], 2) & Hex($aColorArray[3], 2)
EndFunc   ;==>_Color_SetBrightness

Func _Color_GetBrightness($iColor)
    Local $aColorArray[4]

    $aColorArray[1] = _ColorGetRed($iColor)
    $aColorArray[2] = _ColorGetGreen($iColor)
    $aColorArray[3] = _ColorGetBlue($iColor)

    $IndexMax = _ArrayMaxIndex($aColorArray, 1, 1)
    Return Round(($aColorArray[$IndexMax] / 255) * 100, 0)
EndFunc   ;==>_Color_GetBrightness

Func _Color_SetHue($iColor, $iHue)
    Local $aColorArray[4]

    $aColorArray[1] = _ColorGetRed($iColor)
    $aColorArray[2] = _ColorGetGreen($iColor)
    $aColorArray[3] = _ColorGetBlue($iColor)

    $iMax = _ArrayMax($aColorArray, 1, 1)
    $iMin = _ArrayMin($aColorArray, 1, 1)

    If $iHue >= 61 And $iHue <= 180 Then
        $IndexMax = 2
        If $iHue < 120 Then
            $IndexMin = 3
            $iMid = (($iMax - $iMin) * (120 - $iHue)) / 60 + $iMin
        Else
            $IndexMin = 1
            $iMid = (($iMax - $iMin) * ($iHue - 120)) / 60 + $iMin
        EndIf
    ElseIf $iHue >= 181 And $iHue <= 299 Then
        $IndexMax = 3
        If $iHue <= 240 Then
            $IndexMin = 1
            $iMid = (($iMax - $iMin) * (240 - $iHue)) / 60 + $iMin
        Else
            $IndexMin = 2
            $iMid = (($iMax - $iMin) * ($iHue - 240)) / 60 + $iMin
        EndIf
    ElseIf $iHue >= 300 Or $iHue <= 60 Then
        $IndexMax = 1
        If $iHue <= 60 Then
            $IndexMin = 3
            $iMid = (($iMax - $iMin) * ($iHue)) / 60 + $iMin
        Else
            $IndexMin = 2
            $iMid = (($iMax - $iMin) * (360 - $iHue)) / 60 + $iMin
        EndIf
    EndIf
    $IndexMid = 6 - ($IndexMin + $IndexMax)
    $aColorArray[$IndexMin] = $iMin
    $aColorArray[$IndexMax] = $iMax
    $aColorArray[$IndexMid] = $iMid
    Return 0 & "x" & Hex($aColorArray[1], 2) & Hex($aColorArray[2], 2) & Hex($aColorArray[3], 2)
EndFunc   ;==>_Color_SetHue

Func _Color_GetHue($iColor)
    Local $aColorArray[4], $Hue

    $aColorArray[1] = _ColorGetRed($iColor)
    $aColorArray[2] = _ColorGetGreen($iColor)
    $aColorArray[3] = _ColorGetBlue($iColor)

    $IndexMax = _ArrayMaxIndex($aColorArray, 1, 1)
    $IndexMin = _ArrayMinIndex($aColorArray, 1, 1)
    $IndexMid = 6 - ($IndexMax + $IndexMin)
    $Lambda = ($aColorArray[$IndexMid] - $aColorArray[$IndexMin]) * 60 / ($aColorArray[$IndexMax] - $aColorArray[$IndexMin])

    Switch $IndexMax
        Case 1
            Switch $IndexMin
                Case 2
                    $Hue = 360 - $Lambda
                Case 3
                    $Hue = $Lambda
            EndSwitch
        Case 2
            Switch $IndexMin
                Case 1
                    $Hue = 120 + $Lambda
                Case 3
                    $Hue = 120 - $Lambda
            EndSwitch
        Case 3
            Switch $IndexMin
                Case 1
                    $Hue = 240 - $Lambda
                Case 2
                    $Hue = 240 + $Lambda
            EndSwitch
    EndSwitch
    Return Round($Hue, 0)
EndFunc   ;==>_Color_GetHue

Func _Color_FindComplementary($iColor)
    Local $iHue = Mod(_Color_GetHue($iColor) + 180, 360)
    Return _Color_SetHue($iColor, $iHue)
EndFunc   ;==>_Color_FindComplementary

Mfg / Best Regards Spider

www.AutoIt.de - Moderator of the German AutoIt Forum

 

Link to comment
Share on other sites

Thanks GtaSpider,

I'm glad you (someone) like it

and you are fully right that in a gui we see

better what is it about.

See in the first post the same with a "little changed"

gui (using graphics as you proposed)

...

Link to comment
Share on other sites

@grham

I like it !!

very nice

But to get it working in the latest version of AU3.

I had to add the following in the top.

.

#include<Array.au3>
#include<Color.au3>
#include<GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiSlider.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>

regards

ptrex

Edited by ptrex
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...