Jump to content

color fading bg doesn't work


Recommended Posts

it's all in the title... the script will change colors, but its not a fade. it fades from black, then flickers and repeats instead of continuing to fade.

For $x = 0 To 99 Step 1
            Switch $next
                Case 0
                    $r = (0 + $x)
                    $g = 0
                    $b = 0
                    $Color = String("0x" & $r & $g & $b)
                Case 1
                    $r = 99
                    $g = (0 + $x)
                    $b = 0
                    $Color = String("0x" & $r & $g & $b)
                Case 2
                    $r = (99 - $x)
                    $g = 99
                    $b = 0
                    $Color = String("0x" & $r & $g & $b)
                Case 3
                    $r = 0
                    $g = 99
                    $b = (0 + $x)
                    $Color = String("0x" & $r & $g & $b)
                Case 4
                    $r = 0
                    $g = (99 - $x)
                    $b = 99
                    $Color = String("0x" & $r & $g & $b)
                Case 5
                    $r = (0 + $x)
                    $g = 0
                    $b = 99
                    $Color = String("0x" & $r & $g & $b)
                Case 6
                    $r = 99
                    $g = (0 + $x)
                    $b = 99
                    $Color = String("0x" & $r & $g & $b)
                Case 7
                    $r = (99 - $x)
                    $g = 99
                    $b = 99
                    $Color = String("0x" & $r & $g & $b)
                Case 8
                    $r = 0
                    $g = (99 - $x)
                    $b = 99
                    $Color = String("0x" & $r & $g & $b)
                Case 9
                    $r = 0
                    $g = 0
                    $b = (99 - $x)
                    $Color = String("0x" & $r & $g & $b)
            EndSwitch
            GUISetBkColor($Color, $Form1)
            If $ON = True Then ExitLoop
            Sleep(100)
        Next
        $next = $next + 1
        If $next == 10 Then
            $next = 0
        EndIf

its in the main loop. if the program isn't on fade BG colors... its simple addition, and a very noobish way of doing it, but it should work... my problem is it doesnt work fully, only partially.

Link to comment
Share on other sites

Something like this ?

$gui = GUICreate ( "Fade Color", 400, 100 )
GUISetState ( )

For $_I = 0 To 255 Step 5
    $_Color = Hex ( $_I * 256 * 256 + $_I * 256 + $_I, 6 )
    ConsoleWrite ( "$_Color : 0x" & $_Color & @Crlf )
    GUISetBkColor ( "0x" & $_Color, $gui )
    Sleep ( 100 )
Next

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

Try this:

#include <GUIConstantsEx.au3>
$hGUI = GUICreate("GUI Background Color Fading by UEZ", 640, 480)
GUISetState()

AdlibRegister("FadeColor", 50)

While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
GUIDelete()
AdlibUnRegister("FadeColor")
Exit

Func FadeColor()
    Local Static $v = 0
    $red = Hex(0xFF * (Cos($v * 1.10) + 1) / 2, 2)
    $green = Hex(0xFF * (Sin($v * 1.00) + 1) / 2, 2)
    $blue = Hex(0xFF * (Sin($v * 1.20) + 1) / 2, 2)
    GUISetBkColor("0x" & $red & $green & $blue, $hGUI)
    $v += 0.1
EndFunc

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

thats good, but its just a simple fade from black to white.. have to tweak it for a full color range.

Try this Fade Between 2 Colors ! Posted Image

#Include <WinAPIEx.au3>
#include <Math.au3>

Global $_GuiDemo, $_Label1, $_Label2, $_Label3

_Gui ( )
_FadeBetweenColors ( $_GuiDemo, $_Label1, "Example 1", 0xFF8040, 0x0050FF, 100, 100 ) ; orange to blue
Sleep ( 2000 )

_FadeBetweenColors ( $_GuiDemo, $_Label1, "Example 2", 0xFFFFFF, 0x000000, 150 ) ; white to black
Sleep ( 2000 )

_FadeBetweenColors ( $_GuiDemo, $_Label1, "Example 3", 0x000000, 0xFF8040, 60, 150 ) ; black to orange
GUICtrlSetData ( $_Label1, "Finish !" )
Sleep ( 2000 )
Exit

Func _FadeBetweenColors ( $_GUI, $_Label, $_Text, $_Color1, $_Color2, $_Steps=40, $_Delay=50 )
    GUICtrlSetBkColor ( $_Label2, $_Color1 )
    GUICtrlSetColor ( $_Label2, _ColorInverse ( $_Color1 ) )
    GUICtrlSetBkColor ( $_Label3, $_Color2 )
    GUICtrlSetColor ( $_Label3, _ColorInverse ( $_Color2 ) )
    GUICtrlSetData ( $_Label1, $_Text )
    Local $aColor[3] = [_WinAPI_GetRValue ( $_Color1 ), _WinAPI_GetGValue ( $_Color1 ), _WinAPI_GetBValue ( $_Color1 )]
    $_RStep = ( _WinAPI_GetRValue ( $_Color2 ) - $aColor[0] ) / $_Steps
    $_GStep = ( _WinAPI_GetGValue ( $_Color2 ) - $aColor[1] ) / $_Steps
    $_BStep = ( _WinAPI_GetBValue ( $_Color2 ) - $aColor[2] ) / $_Steps
    For $x = 1 To $_Steps Step 1
        $aColor[0] = _Max ( _Min ( $aColor[0] + $_RStep, 255 ), 0 )
        $aColor[1] = _Max ( _Min ( $aColor[1] + $_GStep, 255 ), 0 )
        $aColor[2] = _Max ( _Min ( $aColor[2] + $_BStep, 255 ), 0 )
        If Mod ( $x, 2 ) Then _
            GUICtrlSetColor ( $_Label, _ColorInverse ( '0x' & Hex ( _WinAPI_RGB ( $aColor[0], $aColor[1], $aColor[2] ), 6 ) ) )
        Sleep ( $_Delay )
        GUISetBkColor ( '0x' & Hex ( _WinAPI_RGB ( $aColor[0], $aColor[1], $aColor[2] ), 6 ), $_GUI )
    Next
EndFunc ;==> _FadeBetweenColors ( )

Func _ColorInverse ( $_Color )
    Return BitXOR ( $_Color, 0xFFFFFF )
EndFunc ;==> _ColorInverse ( )

Func _Gui ( )
    $_GuiDemo = GUICreate ( "Fade Between Colors", @DesktopWidth/3, @DesktopHeight/3 )
    GUISetBkColor ( 0xFF8040, $_GuiDemo )
    $_Label1 = GUICtrlCreateLabel ( "", 0, 100, @DesktopWidth/3, 100, 0x01 )
    GUICtrlSetFont ( $_Label1, 60, 900 )
    $_Label2 = GUICtrlCreateLabel ( "Color 1", 20, 20, 50, 50, BitOr ( 0x01, 0x1000 ) )
    $_Label3 = GUICtrlCreateLabel ( "Color 2", @DesktopWidth/3 -20 -50, 20, 50, 50, BitOr ( 0x01, 0x1000 ) )
    GUICtrlSetFont ( $_Label3, 14, 400 )
    GUICtrlSetFont ( $_Label2, 14, 400 )
    GUISetState ( )
EndFunc ;==> _Gui ( )
Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

another unsolicited example.
simple blinky color change clock I made years ago

#NoTrayIcon
Global $varColors[3]
Global $varBlendRates[3]
Global $varBlendDirections[3]
Global $varColor
Global $timer
Global $hover = -1
Global $alpha = 220
Global $active = 1
$varSpeed = 60
$blendtimer = TimerInit()
$updatetimer = TimerInit()
$timer = TimerInit()
$dll = DllOpen("user32.dll")
 
$gui = GUICreate("ColorfulClock",200,70,0,0,0x88880000,-1,WinGetHandle("Program Manager"))
$time = GUICtrlCreateLabel(@HOUR & ":" & @MIN & ":" & @SEC,0,0,200,70,513)
    GUISetOnEvent(-1,"_DragWin")
    GUICtrlSetFont(-1,35)
 
PaintRand()
BlendRates()
 
WinSetTrans("ColorfulClock","",$alpha)
WinSetOnTop("ColorfulClock","",1)
GUISetState()
 
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case -3
            ExitLoop
    EndSwitch

    If $hover and $active and _IsPressed(1,$dll) Then _DragWin()
  
  PaintWin()

    If TimerDiff($timer) >= 3500 Then
        _CheckHover()
    EndIf

    If $hover = False Then
        _FadeClock(-5)
    ElseIf $hover = True Then
        _FadeClock(30)
    EndIf
WEnd
 
Func _IsPressed($sHexKey, $vDLL = 'user32.dll')
    Local $a_R = DllCall($vDLL, "int", "GetAsyncKeyState", "int", '0x' & $sHexKey)
    If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1
    Return 0
EndFunc
 
Func _DragWin()
    _CheckHover()
    If Not $hover Then Return 0
    $mousepos1 = MouseGetPos()
    While _IsPressed(1,$dll)
        $y = 0
        $x = 0
        $mousepos2 = MouseGetPos()
        $x = $mousepos2[0]-$mousepos1[0]
        $y = $mousepos2[1]-$mousepos1[1]
        $mousepos1 = MouseGetPos()
        If $x <> 0 or $y <> 0 Then
            $winpos = WinGetPos("ColorfulClock")
            $winx = $winpos[0] + $x
            If $winx < 0 then $winx = 0
            If $winx > @DesktopWidth - $winpos[2] then $winx = @DesktopWidth - $winpos[2]
            $winy = $winpos[1] + $y
            If $winy <  0 then $winy = 0
            If $winy > @DesktopHeight - $winpos[3] then $winy = @DesktopHeight - $winpos[3]
            WinMove("ColorfulClock","",$winx,$winy)
        EndIf
        PaintWin()
    Wend
EndFunc
 
Func PaintBlend()
    If TimerDiff($blendtimer) > 10000 Then
        $blendtimer = TimerInit()
        BlendRates()
    EndIf
    For $i = 0 to 2
        BlendColors($varColors[$i],$varBlendRates[$i],$varBlendDirections[$i])
    Next
EndFunc
 
Func PaintRand()
    SRandom(Random(1,200))
    For $i = 0 to 2
        $varColors[$i] = Hex(Random(0,255,1),2)
    Next
EndFunc
 
Func BlendRates()
    For $i = 0 to 2
        $varBlendDirections[$i] = Random(0,1,1)
        $varBlendRates[$i] = Random(3,10,1)
    Next
EndFunc
 
Func BlendColors(byref $varThisColor,$varBlendRate,byref $varBlendDir)
    If $varBlendDir = 1 Then
        $varThisColor += $varBlendRate
    Else
        $varThisColor -= $varBlendRate
    EndIf
    If $varThisColor > 255 Then
        $varThisColor -= $varBlendRate
        $varBlendDir = 0
    EndIf
        If $varThisColor < 0 Then
        $varThisColor += $varBlendRate
        $varBlendDir = 1
    EndIf
EndFunc
 
Func PaintWin()
    If TimerDiff($updatetimer) > 999 Then
        $updatetimer = TimerInit()
        GUICtrlSetData($time,@Hour & ":" & @Min & ":" & @SEC)
    EndIf
    PaintBlend()
    $varColor = ""
    For $i = 0 to 2
       $varColor &= Hex(Int($varColors[$i]),2)
    Next
    $val = Hex((Dec("FFFFFF") - Dec($varColor)))
    GUICtrlSetColor($time,"0x" & $val)
    GUISetBkColor("0x" & $varColor)
    sleep($varSpeed)
EndFunc
 
Func _CheckHover()
    $winpos = WinGetPos("ColorfulClock")
    $mousepos = MouseGetPos()
    If ($mousepos[0] >= $winpos[0] And $mousepos[0] <= $winpos[0] + $winpos[2]) And ($mousepos[1] >= $winpos[1] And $mousepos[1] <= $winpos[1] + $winpos[3]) Then
        $timer = TimerInit()
        $hover = True
        $active = True
    Else
        $hover = False
        $active = False
    EndIf
EndFunc
 
Func _FadeClock($direction)
    $alpha += $direction
    If $alpha >= 201 Then
        $alpha = 200
    EndIf
    If $alpha <= 49 Then
        $alpha = 50
    EndIf
    WinSetTrans("ColorfulClock","",$alpha)
EndFunc
Edited by spudw2k
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...