Jump to content

Recommended Posts

Posted

Just some good wishes (and a bit of nonsense) as we head into the holiday season :).

#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

#include <WinApiGdi.au3>
#include <WinApiSysWin.au3>
#include <WindowsSysColorConstants.au3>
#include <GdiPlus.au3>
#include <GuiConstants.au3>

Global $iGuiW = 1280, $iGuiH = 720
Global $iNumItems = 25, $iUpdateInterval = 40

Global $hGUI, $hGraphic, $bPaint

Global Enum $IP_BMP, $IP_X, $IP_Y, $IP_W, $IP_H, $IP_Angle, $IP_Rate, $IP_Dir, $IP_MAX
Global $aItemProps[0][$IP_MAX]
Global $iBkCol = BitOR(0xFF000000, _WinAPI_GetSysColor($COLOR_3DFACE))

Init()
Main()
Cleanup()

Func Init()
    _GDIPlus_Startup()
    GUIRegisterMsg($WM_PAINT, "WM_PAINT")

    $hGUI = GUICreate("", $iGuiW, $iGuiH, -1, -1, $WS_POPUP, BitOR($WS_EX_COMPOSITED, $WS_EX_LAYERED))
    _WinAPI_SetLayeredWindowAttributes($hGUI,  BitAND(0x00FFFFFF, $iBkCol), 0, $LWA_COLORKEY)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    GUISetState()


    For $i = 1 To $iNumItems
        Switch Random(1,7,1)
            Case 1 To 4
                CreateBox(Random(50, 80, 1), Random(50, 90, 1), ($iGuiW - 60)*Random(), $iGuiH*Random())
            Case 5 To 6
                CreateCane(Random(20, 30, 1), Random(50, 90, 1), ($iGuiW - 60)*Random(), $iGuiH*Random())
            Case 7
                CreateMan(Random(40, 50, 1), Random(60, 80, 1), ($iGuiW - 60)*Random(), $iGuiH*Random())
        EndSwitch
    Next
EndFunc

Func CreateBox($iW, $iH, $iX = 0, $iY = 0)
    Local $iIdx = UBound($aItemProps)
    ReDim $aItemProps[$iIdx + 1][$IP_MAX]
    $aItemProps[$iIdx][$IP_W] = $iW
    $aItemProps[$iIdx][$IP_H] = $iH
    $aItemProps[$iIdx][$IP_X] = $iX
    $aItemProps[$iIdx][$IP_Y] = $iY
    $aItemProps[$iIdx][$IP_Rate] = Random(7, 13, 1)/10
    $aItemProps[$iIdx][$IP_Angle] = Round(359 * Random())
    $aItemProps[$iIdx][$IP_Dir] = Random(0,1,1)
    $aItemProps[$iIdx][$IP_BMP] = _GDIPlus_BitmapCreateFromScan0($iW, $iH)

    Local $hItemBmp = $aItemProps[$iIdx][$IP_BMP]
    Local $hItemGraphic = _GDIPlus_ImageGetGraphicsContext($hItemBmp)
    _GDIPlus_GraphicsSetSmoothingMode($hItemGraphic, $GDIP_SMOOTHINGMODE_HIGHQUALITY)

    Local $tSizeF = _GDIPlus_RectFCreate(0.2 * $iW, 0.2 * $iH, 0.6 * $iW, 0.6 * $iH)

    Local $iRibbonCol =  _WinAPI_RGB(Random(0x80,0xFF), Random(0x80,0xFF), Random(0x80,0xFF))
    Local $hRibbonBrush = _GDIPlus_BrushCreateSolid(BitOR(0xFF000000, $iRibbonCol))

    Local $hBrush = _GDIPlus_BrushCreateSolid(BitOR(0xFF000000, _WinAPI_RGB(Random(0x80,0xFF), Random(0x80,0xFF), Random(0x80,0xFF))))
    _GDIPlus_GraphicsDrawRect($hItemGraphic, $tSizeF.X, $tSizeF.Y, $tSizeF.Width, $tSizeF.Height, 0)
    _GDIPlus_GraphicsFillRect($hItemGraphic, $tSizeF.X, $tSizeF.Y, $tSizeF.Width, $tSizeF.Height, $hBrush)

    Local $tSizeF2 = _GDIPlus_RectFCreate(9*$iW/20, 9*$iH/20, ($iW+$iH)/20, ($iW+$iH)/20)
    _GDIPlus_GraphicsFillRect($hItemGraphic,$tSizeF.X, $tSizeF2.Y, $tSizeF.Width, $tSizeF2.Height, $hRibbonBrush)
    _GDIPlus_GraphicsDrawRect($hItemGraphic, $tSizeF.X, $tSizeF2.Y, $tSizeF.Width, $tSizeF2.Height, 0)
    _GDIPlus_GraphicsFillRect($hItemGraphic, $tSizeF2.X, $tSizeF.Y, $tSizeF2.Width, $tSizeF.Height, $hRibbonBrush)
    _GDIPlus_GraphicsDrawRect($hItemGraphic, $tSizeF2.X, $tSizeF.Y, $tSizeF2.Width, $tSizeF.Height, 0)

    _GDIPlus_BrushDispose($hRibbonBrush)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hItemGraphic)
EndFunc

Func CreateCane($iW, $iH, $iX = 0, $iY = 0)
    Local $iIdx = UBound($aItemProps)
    ReDim $aItemProps[$iIdx + 1][$IP_MAX]
    $aItemProps[$iIdx][$IP_W] = $iW
    $aItemProps[$iIdx][$IP_H] = $iH
    $aItemProps[$iIdx][$IP_X] = $iX
    $aItemProps[$iIdx][$IP_Y] = $iY
    $aItemProps[$iIdx][$IP_Rate] = Random(7, 13, 1)/10
    $aItemProps[$iIdx][$IP_Angle] = Round(359 * Random())
    $aItemProps[$iIdx][$IP_Dir] = Random(0,1,1)
    $aItemProps[$iIdx][$IP_BMP] = _GDIPlus_BitmapCreateFromScan0($iW, $iH)

    Local $hItemBmp = $aItemProps[$iIdx][$IP_BMP]
    Local $hItemGraphic = _GDIPlus_ImageGetGraphicsContext($hItemBmp)
    _GDIPlus_GraphicsSetSmoothingMode($hItemGraphic, $GDIP_SMOOTHINGMODE_HIGHQUALITY)

    Local $tSizeF = _GDIPlus_RectFCreate(0.8 * $iW, 0.25 * $iH, 0.1 * $iW, 0.6 * $iH)
    Local $fThk = 0.1 * $iW
    Local $tSizeF2 = _GDIPlus_RectFCreate(0.1 * $iW, 0.1 * $iH, 0.8 * $iW, 0.3 * $iH)
    Local $tSizeF3 = _GDIPlus_RectFCreate($tSizeF2.X + $fThk, $tSizeF2.Y + $fThk, $tSizeF2.Width - 2*$fThk, $tSizeF2.Height - 2*$fThk)


    Local $hPath = _GDIPlus_PathCreate()
    _GDIPlus_PathAddLine($hPath, $tSizeF.X, $tSizeF.Y, $tSizeF.X, $tSizeF.Y + $tSizeF.Height) ;inner
    _GDIPlus_PathAddLine($hPath, $tSizeF.X + $tSizeF.Width, $tSizeF.Y + $tSizeF.Height, $tSizeF.X + $tSizeF.Width, $tSizeF.Y) ;outer
    _GDIPlus_PathAddArc($hPath, $tSizeF2.X, $tSizeF2.Y, $tSizeF2.Width, $tSizeF2.Height, 0, -180) ;outer arc
    _GDIPlus_PathAddArc($hPath, $tSizeF3.X, $tSizeF3.Y, $tSizeF3.Width, $tSizeF3.Height, 180, 180)

    Local $hTextureBmp = _GDIPlus_BitmapCreateFromScan0(20, 20)
    Local $hTextureGraph =  _GDIPlus_ImageGetGraphicsContext($hTextureBmp)
    _GDIPlus_GraphicsClear($hTextureGraph, 0xFFFFFFFF)
    Local $hRedBrush = _GDIPlus_BrushCreateSolid(BitOR(0xFF000000, _WinAPI_RGB(0xFF, 0, 0)))

    Local $aPoints[5][2] = [[4,0]]
    $aPoints[1][0] = -2
    $aPoints[1][1] = -4
    $aPoints[2][0] = 24
    $aPoints[2][1] = 22
    $aPoints[3][0] = 22
    $aPoints[3][1] = 24
    $aPoints[4][0] = -4
    $aPoints[4][1] = -2
    _GDIPlus_GraphicsFillPolygon($hTextureGraph, $aPoints, $hRedBrush)

    For $i = 1 To 2
        For $j = 1 To 4
            $aPoints[$j][1] += $i*10
        Next
        _GDIPlus_GraphicsFillPolygon($hTextureGraph, $aPoints, $hRedBrush)
        For $j = 1 To 4
            $aPoints[$j][1] -= $i*10
            $aPoints[$j][0] += $i*10
        Next
        _GDIPlus_GraphicsFillPolygon($hTextureGraph, $aPoints, $hRedBrush)
        For $j = 1 To 4
            $aPoints[$j][0] -= $i*10
        Next
    Next

    Local $hTexture = _GDIPlus_TextureCreate($hTextureBmp, 0)
    _GDIPlus_GraphicsDrawPath($hItemGraphic, $hPath)
    _GDIPlus_GraphicsFillPath($hItemGraphic, $hPath, $hTexture)


    _GDIPlus_BrushDispose($hRedBrush)
    _GDIPlus_BrushDispose($hTexture)
    _GDIPlus_PathDispose($hPath)
    _GDIPlus_GraphicsDispose($hTextureGraph)
    _GDIPlus_BitmapDispose($hTextureBmp)

    _GDIPlus_GraphicsDispose($hItemGraphic)
EndFunc


Func CreateMan($iW, $iH, $iX = 0, $iY = 0)
    Local $iIdx = UBound($aItemProps)
    ReDim $aItemProps[$iIdx + 1][$IP_MAX]
    $aItemProps[$iIdx][$IP_W] = $iW
    $aItemProps[$iIdx][$IP_H] = $iH
    $aItemProps[$iIdx][$IP_X] = $iX
    $aItemProps[$iIdx][$IP_Y] = $iY
    $aItemProps[$iIdx][$IP_Rate] = Random(7, 13, 1)/10
    $aItemProps[$iIdx][$IP_Angle] = Round(359 * Random())
    $aItemProps[$iIdx][$IP_Dir] = Random(0,1,1)
    $aItemProps[$iIdx][$IP_BMP] = _GDIPlus_BitmapCreateFromScan0($iW, $iH)

    Local $hItemBmp = $aItemProps[$iIdx][$IP_BMP]
    Local $hItemGraphic = _GDIPlus_ImageGetGraphicsContext($hItemBmp)
    _GDIPlus_GraphicsSetSmoothingMode($hItemGraphic, $GDIP_SMOOTHINGMODE_HIGHQUALITY)

    Local $tSizeF = _GDIPlus_RectFCreate(0.3 * $iW, 0.1 * $iH, 0.4 * $iW, 0.25 * $iH)
    Local $tSizeF2 = _GDIPlus_RectFCreate(0.6 * $iW, 0.3 * $iH, 0.1 * $iW, 0.1 * $iH)
    Local $tSizeF3 = _GDIPlus_RectFCreate(0.8 * $iW, 0.35 * $iH, 0.1 * $iW, 0.1 * $iH)
    Local $tSizeF4 = _GDIPlus_RectFCreate(0.7 * $iW, 0.5 * $iH, 0.1 * $iW, 0.1 * $iH)
    Local $tSizeF5 = _GDIPlus_RectFCreate(0.7 * $iW, 0.7 * $iH, 0.2 * $iW, 0.2 * $iH)
    Local $tSizeF6 = _GDIPlus_RectFCreate(0.45 * $iW, 0.7 * $iH, 0.15 * $iW, 0.1 * $iH)
    Local $tSizeF7 = _GDIPlus_RectFCreate(0.1 * $iW, 0.7 * $iH, 0.2 * $iW, 0.2 * $iH)
    Local $tSizeF8 = _GDIPlus_RectFCreate(0.2 * $iW, 0.5 * $iH, 0.1 * $iW, 0.1 * $iH)
    Local $tSizeF9 = _GDIPlus_RectFCreate(0.1 * $iW, 0.35 * $iH, 0.1 * $iW, 0.1 * $iH)
    Local $tSizeF10 = _GDIPlus_RectFCreate(0.3 * $iW, 0.3 * $iH, 0.1 * $iW, 0.1 * $iH)

    Local $hPath = _GDIPlus_PathCreate()
    _GDIPlus_PathAddArc($hPath, $tSizeF.X, $tSizeF.Y, $tSizeF.Width, $tSizeF.Height, 135, 270)
    _GDIPlus_PathAddArc($hPath, $tSizeF2.X, $tSizeF2.Y, $tSizeF2.Width, $tSizeF2.Height,  225, -180)
    _GDIPlus_PathAddArc($hPath, $tSizeF3.X, $tSizeF3.Y, $tSizeF3.Width, $tSizeF3.Height, 250, 180)
    _GDIPlus_PathAddArc($hPath, $tSizeF4.X, $tSizeF4.Y, $tSizeF4.Width, $tSizeF4.Height, 225, -135)
    _GDIPlus_PathAddArc($hPath, $tSizeF5.X, $tSizeF5.Y, $tSizeF5.Width, $tSizeF5.Height, 275, 200)
    _GDIPlus_PathAddArc($hPath, $tSizeF6.X, $tSizeF6.Y, $tSizeF6.Width, $tSizeF6.Height, 0, -135)
    _GDIPlus_PathAddArc($hPath, $tSizeF7.X, $tSizeF7.Y, $tSizeF7.Width, $tSizeF7.Height, 65, 200)
    _GDIPlus_PathAddArc($hPath, $tSizeF8.X, $tSizeF8.Y, $tSizeF8.Width, $tSizeF8.Height, 90, -135)
    _GDIPlus_PathAddArc($hPath, $tSizeF9.X, $tSizeF9.Y, $tSizeF9.Width, $tSizeF9.Height, 110, 180)
    _GDIPlus_PathAddArc($hPath, $tSizeF10.X, $tSizeF10.Y, $tSizeF10.Width, $tSizeF10.Height, 135, -180)

    Local $hBrush = _GDIPlus_BrushCreateSolid(BitOR(0xFF000000, _WinAPI_RGB(0xF0, 0xE0, 0xA0)))
    Local $hButtonsBrush = _GDIPlus_BrushCreateSolid(BitOR(0xFF000000, _WinAPI_RGB(Random(0x0, 0xFF, 1), Random(0x0, 0xFF, 1), Random(0x0, 0xFF, 1))))
    Local $hMouthBrush = _GDIPlus_BrushCreateSolid(BitOR(0xFF000000, _WinAPI_RGB(0x80, 0, 0)))

    _GDIPlus_GraphicsFillPath($hItemGraphic, $hPath, $hBrush)
    _GDIPlus_GraphicsDrawPath($hItemGraphic, $hPath)

    _GDIPlus_GraphicsFillEllipse($hItemGraphic, 0.37 * $iW, 0.175 * $iH, 0.1 * $iW, 0.1 * $iW, 0)
    _GDIPlus_GraphicsFillEllipse($hItemGraphic, 0.53 * $iW, 0.175 * $iH, 0.1 * $iW, 0.1 * $iW, 0)
    _GDIPlus_GraphicsFillPie($hItemGraphic, 0.4 * $iW, 0.24 * $iH, 0.2 * $iW, 0.1 * $iW, 0, 180, $hMouthBrush)

    _GDIPlus_GraphicsDrawEllipse($hItemGraphic, 0.45 * $iW, 0.45 * $iH, 0.1 * $iW, 0.1 * $iW, 0)
    _GDIPlus_GraphicsFillEllipse($hItemGraphic, 0.45 * $iW, 0.45 * $iH, 0.1 * $iW, 0.1 * $iW, $hButtonsBrush)
    _GDIPlus_GraphicsDrawEllipse($hItemGraphic, 0.45 * $iW, 0.55 * $iH, 0.1 * $iW, 0.1 * $iW, 0)
    _GDIPlus_GraphicsFillEllipse($hItemGraphic, 0.45 * $iW, 0.55 * $iH, 0.1 * $iW, 0.1 * $iW, $hButtonsBrush)

    _GDIPlus_PathDispose($hPath)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_BrushDispose($hButtonsBrush)
    _GDIPlus_BrushDispose($hMouthBrush)
    _GDIPlus_GraphicsDispose($hItemGraphic)
EndFunc


Func DropItems()
    Local $hItemBmp, $iX, $iY, $iW, $iH, $iAngle, $fRate, $iShift

    If Not _GDIPlus_GraphicsClear($hGraphic, $iBkCol) Then Return

    For $i = 0 To UBound($aItemProps) - 1
        $hItemBmp = $aItemProps[$i][$IP_BMP]
        $iAngle = $aItemProps[$i][$IP_Angle]
        $iX = $aItemProps[$i][$IP_X]
        $iY = $aItemProps[$i][$IP_Y]
        $iW = $aItemProps[$i][$IP_W]
        $iH = $aItemProps[$i][$IP_H]
        $fRate =  $aItemProps[$i][$IP_Rate]
        $iShift = ($aItemProps[$i][$IP_Dir]) ? 2 : -2
        $iAngle = Mod($iAngle + 2*Random() + $iShift, 360)
        $iY = Mod($iY + $iH + (10 * $fRate), $iGuiH + $iH) - $iH
        $iX += (4*Random() - 2)

        _GDIPlus_GraphicsTranslateTransform($hGraphic, $iW/2 + $iX, $iH/2 + $iY)
        _GDIPlus_GraphicsRotateTransform($hGraphic, $iAngle)
        _GDIPlus_GraphicsTranslateTransform($hGraphic, -($iW/2 + $iX), -($iH/2 + $iY))
        _GDIPlus_GraphicsDrawImage($hGraphic, $hItemBmp, $iX, $iY)
        _GDIPlus_GraphicsResetTransform($hGraphic)

        $aItemProps[$i][$IP_Angle] = $iAngle
        $aItemProps[$i][$IP_X] = $iX
        $aItemProps[$i][$IP_Y] = $iY
    Next
EndFunc

Func Main()
    Local $hTimer = TimerInit()

    Do
        If TimerDiff($hTimer) > $iUpdateInterval Then
            $bPaint = True
            _WinAPI_InvalidateRect($hGUI)
            $hTimer = TimerInit()
        EndIf
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc

Func WM_PAINT($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam, $lParam

    If $bPaint Then
        $bPaint = False
        DropItems()
    EndIf

    Return 1
EndFunc

Func Cleanup()
    GUIRegisterMsg($WM_PAINT, 0)
    For $i = 0 To UBound($aItemProps) - 1
        _GDIPlus_BitmapDispose($aItemProps[$i][$IP_BMP])
    Next
    _GDIPlus_GraphicsDispose($hGraphic)
    GUIDelete($hGUI)
    _GDIPlus_Shutdown()
EndFunc

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
×
×
  • Create New...