Mikeman27294 Posted September 12, 2011 Posted September 12, 2011 (edited) Hey everyone. I want to add a theming engine to a program of mine, so that there is multiple hues, ie red, green, orange, blue and so on. I also want to be able to change the brightness of the background, ie you can choose between a range oflight greys through to dark greys. I have searched the forum and came across this: #include<Array.au3> #include<Color.au3> #include<GUIConstantsEx.au3> expandcollapse popupGUICreate("",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 However, I dont quite understand the hue changing function in this, or the brightness function. Are there any easier ways to do something like this? Otherwise, can someone please help me make sense of the hue and brightness functions? Thanks. Finally the autoit tags are working so there u go. Sorry bouth that, it was only showing the first few lines and then it swallowed up the edit button and all those buttons and so on. Edited September 13, 2011 by Mikeman27294
MvGulik Posted September 12, 2011 Posted September 12, 2011 (edited) Try passing the code, after first switching the post editor in code mode. An post it in that mode to(if posting in normal mode also screws things up.) ... Erm: Yep ... Don't post in Normal mode Grr: ... don't even switch to normal mode ... test: (will be removed again) (guess not yet ... ) expandcollapse popup#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 Last 'Done' (I Hope) edit ... yep. (all edit-code mode, no normal edit-mode involved.) Edited September 13, 2011 by iEvKI3gv9Wrkd41u "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ...
taietel Posted September 12, 2011 Posted September 12, 2011 Take a look Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text
UEZ Posted September 12, 2011 Posted September 12, 2011 You can checkout or Br,UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Mikeman27294 Posted September 13, 2011 Author Posted September 13, 2011 Thanks guys. That image tool looks like it is exactly what will answer my question.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now