Glow- bzw. Lichteffekt!?

  • Hi,

    bei meinem neuesten Projekt, geht es um ein Programm welches RGBW-Leds ansteuert. Dazu möchte ich eine grafische Oberfläche programmieren. Es sind ca. 20 Led´s anzusteuern, welche jeweils ca. 4000 verschiedene Farben in 10 Helligkeitsstufen darstellen können.

    Mein Problem ist nicht die Ansteuerung der Led´s selbst, sonder die Darstellung in der GUI. Ich denke, mit einem Glow effekt sollte das machbar sein.
    Allerdings weiss ich nicht wie man das realisiert. Habt ihr schonmal was ähnliches gemacht?

    Wäre super nett wenn ihr mir nen kleinen Codeschnipsel geben könntet.

    Danke
    Gruß Daniel

    Einmal editiert, zuletzt von danielsan85 (10. Januar 2011 um 18:25)

  • Mit den PathBrush-Funktionen kann man einiges machen:

    Spoiler anzeigen
    [autoit]

    #include "GDIP.au3"
    #include <GDIPlus.au3>
    #include <GUIConstantsEx.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $iLX = 40
    Global $iLY = 20
    Global $iLS = 20

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Global $hGui = GUICreate("LED", $iLX * $iLS, $iLY * $iLS)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()
    Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)

    [/autoit] [autoit][/autoit] [autoit]

    Global $hBmpBuffer = _GDIPlus_BitmapCreateFromGraphics($iLX * $iLS, $iLY * $iLY, $hGraphics)
    Global $hGfxBuffer = _GDIPlus_ImageGetGraphicsContext($hBmpBuffer)
    _GDIPlus_GraphicsSetSmoothingMode($hGfxBuffer, 2)

    [/autoit] [autoit][/autoit] [autoit]

    Global $hBmpLED_ON = _CreateLED($hGraphics, $iLS, 0xFFFFFFFF, 0xFF00FF00, True)
    Global $hBmpLED_OFF = _CreateLED($hGraphics, $iLS, 0xFF777777, 0x88066000, False)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While 1
    _GDIPlus_GraphicsClear($hGfxBuffer, 0xFF000000)
    For $x = 0 To $iLX - 1
    For $y = 0 To $iLY - 1
    _GDIPlus_GraphicsDrawImage($hGfxBuffer, $hBmpLED_OFF, $x * $iLS - $iLS / 2, $y * $iLS - $iLS / 2)
    Next
    Next
    For $x = 0 To $iLX - 1
    For $y = 0 To $iLY - 1
    If Random(0, 2, 1) = 1 Then _GDIPlus_GraphicsDrawImage($hGfxBuffer, $hBmpLED_ON, $x * $iLS - $iLS / 2, $y * $iLS - $iLS / 2)
    Next
    Next
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
    Sleep(1000)
    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _CreateLED($hGraphics, $iLS, $iColor1 = 0xFFFFFFFF, $iColor2 = 0xFF00FF00, $bOn = True)
    Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iLS * 2, $iLS * 2, $hGraphics)
    Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hContext, 2)

    [/autoit] [autoit][/autoit] [autoit]

    If $bOn Then
    Local $hPath = _GDIPlus_PathCreate()
    _GDIPlus_PathAddEllipse($hPath, 0, 0, $iLS * 2, $iLS * 2)
    Local $hBrush = _GDIPlus_PathBrushCreateFromPath($hPath)
    _GDIPlus_PathBrushSetSigmaBlend($hBrush, 0.6, 0.7)
    _GDIPlus_PathBrushSetCenterColor($hBrush, $iColor2)
    Local $aColor[2] = [1, 0x00FFFFFF]
    _GDIPlus_PathBrushSetSurroundColorsWithCount($hBrush, $aColor)
    _GDIPlus_PathDispose($hPath)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_GraphicsFillEllipse($hContext, 0, 0, $iLS * 2, $iLS * 2, $hBrush)
    _GDIPlus_BrushDispose($hBrush)
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    $hPath = _GDIPlus_PathCreate()
    _GDIPlus_PathAddEllipse($hPath, $iLS / 2, $iLS / 2, $iLS, $iLS)
    $hBrush = _GDIPlus_PathBrushCreateFromPath($hPath)
    _GDIPlus_PathBrushSetSigmaBlend($hBrush, 1, 0.6)
    _GDIPlus_PathBrushSetGammaCorrection($hBrush, True)
    _GDIPlus_PathBrushSetCenterPoint($hBrush, $iLS * 0.9, $iLS * 0.9)
    _GDIPlus_PathBrushSetCenterColor($hBrush, $iColor1)
    Local $aColor[2] = [1, $iColor2]
    _GDIPlus_PathBrushSetSurroundColorsWithCount($hBrush, $aColor)
    _GDIPlus_PathDispose($hPath)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_GraphicsFillEllipse($hContext, $iLS / 2, $iLS / 2, $iLS, $iLS, $hBrush)
    _GDIPlus_BrushDispose($hBrush)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_GraphicsDispose($hContext)
    Return $hBitmap
    EndFunc ;==>_CreateLED

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func WM_PAINT($hWnd, $uMsgm, $wParam, $lParam)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_PAINT

    [/autoit] [autoit][/autoit] [autoit]

    Func _Exit()
    _GDIPlus_BitmapDispose($hBmpLED_ON)
    _GDIPlus_BitmapDispose($hBmpLED_OFF)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_GraphicsDispose($hGfxBuffer)
    _GDIPlus_BitmapDispose($hBmpBuffer)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    Exit
    EndFunc ;==>_Exit

    [/autoit]

    Die GDIp.au3 wird benötigt - findest du im Forum.
    schau dir auch noch die restlichen PathBrush-Funktionen an, und probier sie aus um evtl. bessere Effekte zu erreichen

    E

  • Hi,

    erstmal Danke. Aber ich kann die GDIp.au3 nicht finden. Wenn ich die Suche bemühe finde ich nur dieses Thema!

    Kannst du das Script noch ein bisschen abspeken? So das nur eine LED zu sehen ist ohne viel schnick schnack?

    Danke
    Gruß Daniel

  • hier der original Link zu GDIp.au3: http://www.autoitscript.com/forum/topic/10…post__p__748870

    Hier eine Version, die alle Farben und Helligkeiten kann:

    Spoiler anzeigen
    [autoit]

    #include "GDIP.au3"
    #include <GDIPlus.au3>
    #include <GUIConstantsEx.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $iLS = 20

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    Global $hGui = GUICreate("LED", $iLS * 6, $iLS * 2 + 200)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    Global $cDummyHUE = GUICtrlCreateDummy()
    For $i = 0 To 4
    GUICtrlCreateSlider($iLS * $i + $iLS / 2, $iLS * 2 + 10, 20, 90, 0x0002)
    GUICtrlSetData(-1, $i * 20)
    Next
    Global $cDummyLIG = GUICtrlCreateDummy()
    For $i = 0 To 4
    GUICtrlCreateSlider($iLS * $i + $iLS / 2, $iLS * 2 + 100, 20, 90, 0x0002)
    Next
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()
    Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
    Global $hBmpBuffer = _GDIPlus_BitmapCreateFromGraphics($iLS * 6, $iLS * 2, $hGraphics)
    Global $hGfxBuffer = _GDIPlus_ImageGetGraphicsContext($hBmpBuffer)
    _GDIPlus_GraphicsSetSmoothingMode($hGfxBuffer, 2)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While 1
    _GDIPlus_GraphicsClear($hGfxBuffer, 0xFF000000)
    For $i = 0 To 4
    _DrawLED($i)
    Next
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
    Sleep(50)
    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _DrawLED($iI)
    Local $iHUE = GUICtrlRead($cDummyHUE + $iI + 1) / 100
    Local $iLIG = 0.5 - GUICtrlRead($cDummyLIG + $iI + 1) / 200
    Local $iColor = _HSLAtoARGB($iHUE, 1, $iLIG, 1)
    Local $iColor2 = BitOR(BitShift($iLIG * 2 * 0xFF, -24), 0x00FFFFFF)
    If $iI = 0 Then ConsoleWrite(Hex($iColor2) & @CRLF)
    Local $hPath = _GDIPlus_PathCreate()
    _GDIPlus_PathAddEllipse($hPath, $iI * $iLS, 0, $iLS * 2, $iLS * 2)
    Local $hBrush = _GDIPlus_PathBrushCreateFromPath($hPath)
    _GDIPlus_PathBrushSetSigmaBlend($hBrush, 0.5, 0.7)
    _GDIPlus_PathBrushSetCenterColor($hBrush, $iColor)
    Local $aColor[2] = [1, 0x00FFFFFF]
    _GDIPlus_PathBrushSetSurroundColorsWithCount($hBrush, $aColor)
    _GDIPlus_PathDispose($hPath)
    _GDIPlus_GraphicsFillEllipse($hGfxBuffer, $i * $iLS, 0, $iLS * 2, $iLS * 2, $hBrush)
    _GDIPlus_BrushDispose($hBrush)

    [/autoit] [autoit][/autoit] [autoit]

    $hPath = _GDIPlus_PathCreate()
    _GDIPlus_PathAddEllipse($hPath, $iI * $iLS + $iLS / 2, $iLS / 2, $iLS, $iLS)
    $hBrush = _GDIPlus_PathBrushCreateFromPath($hPath)
    _GDIPlus_PathBrushSetSigmaBlend($hBrush, 1, 0.6)
    _GDIPlus_PathBrushSetGammaCorrection($hBrush, True)
    _GDIPlus_PathBrushSetCenterPoint($hBrush, $iI * $iLS + $iLS * 0.9, $iLS * 0.9)
    _GDIPlus_PathBrushSetCenterColor($hBrush, $iColor2)
    Local $aColor[2] = [1, $iColor]
    _GDIPlus_PathBrushSetSurroundColorsWithCount($hBrush, $aColor)
    _GDIPlus_PathDispose($hPath)
    _GDIPlus_GraphicsFillEllipse($hGfxBuffer, $i * $iLS, 0, $iLS * 2, $iLS * 2, $hBrush)
    _GDIPlus_BrushDispose($hBrush)
    EndFunc ;==>_DrawLED

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _HSLAtoARGB($nH, $nS, $nL, $nA)
    Local $nR, $nG, $nB
    Local $nValB = $nL * ($nS + 1)
    Local $nValA = 2 * $nL - $nValB

    [/autoit] [autoit][/autoit] [autoit]

    $nR = _HueToRGB($nValA, $nValB, $nH + 1 / 3)
    $nG = _HueToRGB($nValA, $nValB, $nH)
    $nB = _HueToRGB($nValA, $nValB, $nH - 1 / 3)

    [/autoit] [autoit][/autoit] [autoit]

    Return BitOR(BitShift($nA * 0xFF, -24), BitShift($nR * 0xFF, -16), BitShift($nG * 0xFF, -8), $nB * 0xFF)
    EndFunc ;==>_HSLAtoARGB

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _HueToRGB($nA, $nB, $nH)
    If $nH < 0 Then $nH += 1
    If $nH > 1 Then $nH -= 1

    [/autoit] [autoit][/autoit] [autoit]

    If (6 * $nH) < 1 Then Return $nA + ($nB - $nA) * 6 * $nH
    If (2 * $nH) < 1 Then Return $nB
    If (3 * $nH) < 2 Then Return $nA + ($nB - $nA) * 6 * (2 / 3 - $nH)
    Return $nA
    EndFunc ;==>_HueToRGB

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func WM_PAINT($hWnd, $uMsgm, $wParam, $lParam)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_PAINT

    [/autoit] [autoit][/autoit] [autoit]

    Func _Exit()
    _GDIPlus_GraphicsDispose($hGfxBuffer)
    _GDIPlus_BitmapDispose($hBmpBuffer)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    Exit
    EndFunc ;==>_Exit

    [/autoit]

    E

  • Coole Sache!

    Da hab ich ja jetzt gut was zu tun, bis ich den Quelltext durchgearbeitet und verstanden hab.
    Sieht aber genau so aus wie ich mir das vorgestellt hab.
    Du sagst das kann alle Farben, auch weiss? Ich hab nur ein sehr helles Türkis hinbekommen. Grautöne fehlen mir auch. Denn wenn eine Led mal aus ist würde ich sie gerne dunkelgrau darstellen.

    Danke
    Daniel

  • Eine LED besteht (in meinem Beispiel) aus 2 Ellipsen; eine für Glow und eine für LED
    Bei beiden kannst du die Farbe selber angeben
    _GDIPlus_PathBrushSetCenterColor = Farbe im Mittelpunkt
    _GDIPlus_PathBrushSetSurroundColorsWithCount = Farbe am Rand

    Wenn du da etwas herumprobierst, wirst du selber eine weiße LED hinbekommen ^^

    E

    EDIT: bei _HSLAtoARGB kann man auch Saturation angeben; sollten Werte von 0-1 sein