#include <Array.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)

Global $iWidth = 800;@DesktopWidth
Global $iHeight = 580;@DesktopHeight

Global Const $iSizeX = 300
Global Const $iSizeY = 300
Global Const $iSizeZ = 300
Global Const $iMinSize = 10
Global Const $iMaxSize = 30
Global Const $iMinSpeed = 1
Global Const $iMaxSpeed = 7

Global $aColors[7] = [6, 0xFFFF0000, 0xFF00FF00, 0xFF0000FF, 0xFFFFFF00, 0xFF00FFFF, 0xFFFF00FF]

_GDIPlus_Startup()
Global $hGui = GUICreate("Test", $iWidth, $iHeight)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
Global $hBmpBuffer = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics)
Global $hGfxBuffer = _GDIPlus_ImageGetGraphicsContext($hBmpBuffer)
_GDIPlus_GraphicsSetSmoothingMode($hGfxBuffer, 2)
_GDIPlus_GraphicsClear($hGfxBuffer, 0xFF000000)

Global $hPen = _GDIPlus_PenCreate(0xFF0088FF, 3)
Global $hBrush = _GDIPlus_BrushCreateSolid(0x00000000)

Global $aBall = _InitBalls(25)
Global $aIndex[$aBall[0][0]][2]

Global $tWarpX, $tWarpY, $tWarpZ
_CreateWarpPoints($tWarpX, $tWarpY, $tWarpZ, 0.14)
Global $hBmpBG = _CreateBackGround($tWarpX, $tWarpY, 5)

GUIRegisterMsg($WM_PAINT, "WM_PAINT")
GUIRegisterMsg($WM_ERASEBKGND, "WM_ERASEBKGND")

GUISetState()


Global $iTimer = TimerInit(), $fTime = 0, $iCnt = 0
While 1
	$iTimer = TimerInit()
	_Calc()
	_Draw()
	Sleep(10)
	$fTime += TimerDiff($iTimer)
	$iCnt += 1
	WinSetTitle($hGui, "", "3D Balls  FPS:" & Round(1000 / ($fTime / $iCnt), 1))
WEnd


Func _Calc()
	Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePath", "int", 0, "int*", 0)
	Local $hPathX = $aResult[2]
	$aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePath", "int", 0, "int*", 0)
	Local $hPathY = $aResult[2]

	For $i = 1 To $aBall[0][0]
		$aBall[$i][0] += $aBall[$i][3]
		If $aBall[$i][0] - $aBall[$i][6] / 2 < 0 Or $aBall[$i][0] + $aBall[$i][6] / 2 > $iSizeX Then $aBall[$i][3] *= -1
		$aBall[$i][1] += $aBall[$i][4]
		If $aBall[$i][1] - $aBall[$i][6] / 2 < 0 Or $aBall[$i][1] + $aBall[$i][6] / 2 > $iSizeY Then $aBall[$i][4] *= -1
		$aBall[$i][2] += $aBall[$i][5]
		If $aBall[$i][2] - $aBall[$i][6] / 2 < 0 Or $aBall[$i][2] + $aBall[$i][6] / 2 > $iSizeZ Then $aBall[$i][5] *= -1

		DllCall($ghGDIPDll, "uint", "GdipAddPathLine", "hwnd", $hPathX, "float", $aBall[$i][0], "float", $iSizeZ - $aBall[$i][2], "float", $aBall[$i][0] + $aBall[$i][6], "float", $iSizeZ - $aBall[$i][2])
		DllCall($ghGDIPDll, "uint", "GdipClosePathFigure", "hwnd", $hPathX)
		DllCall($ghGDIPDll, "uint", "GdipAddPathLine", "hwnd", $hPathY, "float", $aBall[$i][2], "float", $aBall[$i][1], "float", $aBall[$i][2] + $aBall[$i][6], "float", $aBall[$i][1])
		DllCall($ghGDIPDll, "uint", "GdipClosePathFigure", "hwnd", $hPathY)

		$aIndex[$i - 1][0] = $aBall[$i][2]
		$aIndex[$i - 1][1] = $i
	Next

	_ArraySort($aIndex, 1)

	DllCall($ghGDIPDll, "uint", "GdipWarpPath", "hwnd", $hPathX, "hwnd", 0, "ptr", DllStructGetPtr($tWarpX), "int", 4, "float", 0, "float", 0, "float", $iSizeX, "float", $iSizeZ, "int", 0, "float", 0)
	DllCall($ghGDIPDll, "uint", "GdipWarpPath", "hwnd", $hPathY, "hwnd", 0, "ptr", DllStructGetPtr($tWarpY), "int", 4, "float", 0, "float", 0, "float", $iSizeZ, "float", $iSizeY, "int", 0, "float", 0)

	Local $tPointsX = DllStructCreate("float[" & $aBall[0][0] * 4 & "];")
	DllCall($ghGDIPDll, "uint", "GdipGetPathPoints", "hwnd", $hPathX, "ptr", DllStructGetPtr($tPointsX), "int", $aBall[0][0] * 2)

	Local $tPointsY = DllStructCreate("float[" & $aBall[0][0] * 4 & "];")
	DllCall($ghGDIPDll, "uint", "GdipGetPathPoints", "hwnd", $hPathY, "ptr", DllStructGetPtr($tPointsY), "int", $aBall[0][0] * 2)

	Local $fSize
	For $i = 1 To $aBall[0][0]
		$fSize = DllStructGetData($tPointsX, 1, ($i - 1) * 4 + 3) - DllStructGetData($tPointsX, 1, ($i - 1) * 4 + 1)
		$aBall[$i][7] = DllStructGetData($tPointsX, 1, ($i - 1) * 4 + 1) - $fSize / 2
		$aBall[$i][8] = DllStructGetData($tPointsY, 1, ($i - 1) * 4 + 2) - $fSize / 2
		$aBall[$i][9] = $fSize
	Next

	DllCall($ghGDIPDll, "uint", "GdipDeletePath", "hwnd", $hPathX)
	DllCall($ghGDIPDll, "uint", "GdipDeletePath", "hwnd", $hPathY)
EndFunc   ;==>_Calc




Func _Draw()
	_GDIPlus_GraphicsDrawImage($hGfxBuffer, $hBmpBG, 0, 0)

	Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePath", "int", 1, "int*", 0)
	Local $hPath = $aResult[2]

	For $i = 1 To $aBall[0][0]
		DllCall($ghGDIPDll, "uint", "GdipAddPathEllipse", "hwnd", $hPath, "float", $aBall[$i][0] - $aBall[$i][6] * 0.5, "float", $iSizeZ - ($aBall[$i][2] + $aBall[$i][6] * 0.5), "float", $aBall[$i][6], "float", $aBall[$i][6])
	Next
	DllCall($ghGDIPDll, "uint", "GdipWarpPath", "hwnd", $hPath, "hwnd", 0, "ptr", DllStructGetPtr($tWarpX), "int", 4, "float", 0, "float", 0, "float", $iSizeX, "float", $iSizeZ, "int", 0, "float", 0)
	_GDIPlus_BrushSetSolidColor($hBrush, 0x55000000)
	DllCall($ghGDIPDll, "uint", "GdipFillPath", "hwnd", $hGfxBuffer, "hwnd", $hBrush, "hwnd", $hPath)
	DllCall($ghGDIPDll, "uint", "GdipDeletePath", "hwnd", $hPath)

	Local $iI
	For $i = 1 To $aBall[0][0]
		$iI = $aIndex[$i - 1][1]
		DllCall($ghGDIPDll, "int", "GdipDrawImageRect", "handle", $hGfxBuffer, "handle", $aBall[$iI][10], "float", $aBall[$iI][7], "float", $aBall[$iI][8], "float", $aBall[$iI][9], "float", $aBall[$iI][9])
		_GDIPlus_BrushSetSolidColor($hBrush, BitShift($aBall[$iI][2] * 0xBB / $iSizeZ, -24))
		DllCall($ghGDIPDll, "int", "GdipFillEllipse", "handle", $hGfxBuffer, "handle", $hBrush, "float", $aBall[$iI][7], "float", $aBall[$iI][8], "float", $aBall[$iI][9], "float", $aBall[$iI][9])
	Next

	_GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
EndFunc   ;==>_Draw



Func _FillLineBrushPolygon($hGraphics, $fX1, $fY1, $fX2, $fY2, $fX3, $fY3, $fX4, $fY4, $iI1, $iI2, $iColor1, $iColor2)
	Local $tPoints = DllStructCreate("float[8];")
	DllStructSetData($tPoints, 1, $fX1, 1)
	DllStructSetData($tPoints, 1, $fY1, 2)
	DllStructSetData($tPoints, 1, $fX2, 3)
	DllStructSetData($tPoints, 1, $fY2, 4)
	DllStructSetData($tPoints, 1, $fX3, 5)
	DllStructSetData($tPoints, 1, $fY3, 6)
	DllStructSetData($tPoints, 1, $fX4, 7)
	DllStructSetData($tPoints, 1, $fY4, 8)

	Local $tPoint1 = DllStructCreate("float;float")
	Local $tPoint2 = DllStructCreate("float;float")

	DllStructSetData($tPoint1, 1, DllStructGetData($tPoints, 1, ($iI1 - 1) * 2 + 1))
	DllStructSetData($tPoint1, 2, DllStructGetData($tPoints, 1, ($iI1 - 1) * 2 + 2))
	DllStructSetData($tPoint2, 1, DllStructGetData($tPoints, 1, ($iI2 - 1) * 2 + 1))
	DllStructSetData($tPoint2, 2, DllStructGetData($tPoints, 1, ($iI2 - 1) * 2 + 2))

	Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateLineBrush", "ptr", DllStructGetPtr($tPoint1), "ptr", DllStructGetPtr($tPoint2), "uint", $iColor1, "uint", $iColor2, "int", 1, "int*", 0)
	Local $hBrush = $aResult[6]

	DllCall($ghGDIPDll, "int", "GdipFillPolygon", "handle", $hGraphics, "handle", $hBrush, "ptr", DllStructGetPtr($tPoints), "int", 4, "int", "FillModeAlternate")

	_GDIPlus_BrushDispose($hBrush)
EndFunc   ;==>_FillLineBrushPolygon

Func _CreateBackGround($tWarpX, $tWarpY, $iTile, $iColor1 = 0xFF020204, $iColor2 = 0xFF131326, $iColor3 = 0xFF242448)
	Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics)
	Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
	_GDIPlus_GraphicsSetSmoothingMode($hContext, 2)
	_GDIPlus_GraphicsClear($hContext, 0xFF000000)

	_FillLineBrushPolygon($hContext, 0, 0, DllStructGetData($tWarpY, 1, 3), DllStructGetData($tWarpY, 1, 4), DllStructGetData($tWarpY, 1, 7), DllStructGetData($tWarpY, 1, 8), 0, $iHeight, 2, 4, $iColor1, $iColor2)
	_FillLineBrushPolygon($hContext, 0, 0, DllStructGetData($tWarpX, 1, 1), DllStructGetData($tWarpY, 1, 4), DllStructGetData($tWarpX, 1, 3), DllStructGetData($tWarpY, 1, 4), $iWidth, 0, 2, 4, $iColor1, $iColor2)
	_FillLineBrushPolygon($hContext, DllStructGetData($tWarpX, 1, 1), DllStructGetData($tWarpY, 1, 4), DllStructGetData($tWarpX, 1, 3), DllStructGetData($tWarpY, 1, 4), DllStructGetData($tWarpX, 1, 3), DllStructGetData($tWarpY, 1, 8), DllStructGetData($tWarpX, 1, 1), DllStructGetData($tWarpY, 1, 8), 1, 3, $iColor1, $iColor2)
	_FillLineBrushPolygon($hContext, DllStructGetData($tWarpX, 1, 3), DllStructGetData($tWarpY, 1, 4), $iWidth, 0, $iWidth, $iHeight, DllStructGetData($tWarpX, 1, 3), DllStructGetData($tWarpY, 1, 8), 1, 3, $iColor2, $iColor3)
	_FillLineBrushPolygon($hContext, DllStructGetData($tWarpX, 1, 1), DllStructGetData($tWarpX, 1, 2), DllStructGetData($tWarpX, 1, 3), DllStructGetData($tWarpX, 1, 4), $iWidth, $iHeight, 0, $iHeight, 1, 3, $iColor2, $iColor3)

	Local $hPen = _GDIPlus_PenCreate(0xFF656565, 1)

	Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePath", "int", 0, "int*", 0)
	Local $hPathX = $aResult[2]
	$aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePath", "int", 0, "int*", 0)
	Local $hPathY = $aResult[2]
	$aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePath", "int", 0, "int*", 0)
	Local $hPathZ = $aResult[2]

	Local $fX, $fY, $fZ
	For $i = 0 To $iTile
		$fX = $i * $iSizeX / $iTile
		$fY = $i * $iSizeY / $iTile
		$fZ = $i * $iSizeZ / $iTile

		DllCall($ghGDIPDll, "uint", "GdipAddPathLine", "hwnd", $hPathX, "float", $fX, "float", 0, "float", $fX, "float", $iSizeZ)
		DllCall($ghGDIPDll, "uint", "GdipClosePathFigure", "hwnd", $hPathX)
		DllCall($ghGDIPDll, "uint", "GdipAddPathLine", "hwnd", $hPathX, "float", 0, "float", $fZ, "float", $iSizeX, "float", $fZ)
		DllCall($ghGDIPDll, "uint", "GdipClosePathFigure", "hwnd", $hPathX)

		DllCall($ghGDIPDll, "uint", "GdipAddPathLine", "hwnd", $hPathY, "float", $fZ, "float", 0, "float", $fZ, "float", $iSizeY)
		DllCall($ghGDIPDll, "uint", "GdipClosePathFigure", "hwnd", $hPathY)
		DllCall($ghGDIPDll, "uint", "GdipAddPathLine", "hwnd", $hPathY, "float", 0, "float", $fY, "float", $iSizeZ, "float", $fY)
		DllCall($ghGDIPDll, "uint", "GdipClosePathFigure", "hwnd", $hPathY)

		DllCall($ghGDIPDll, "uint", "GdipAddPathLine", "hwnd", $hPathZ, "float", $fX, "float", 0, "float", $fX, "float", $iSizeY)
		DllCall($ghGDIPDll, "uint", "GdipClosePathFigure", "hwnd", $hPathZ)
		DllCall($ghGDIPDll, "uint", "GdipAddPathLine", "hwnd", $hPathZ, "float", 0, "float", $fY, "float", $iSizeX, "float", $fY)
		DllCall($ghGDIPDll, "uint", "GdipClosePathFigure", "hwnd", $hPathZ)
	Next

	DllCall($ghGDIPDll, "uint", "GdipWarpPath", "hwnd", $hPathX, "hwnd", 0, "ptr", DllStructGetPtr($tWarpX), "int", 4, "float", 0, "float", 0, "float", $iSizeX, "float", $iSizeZ, "int", 0, "float", 0)
	DllCall($ghGDIPDll, "uint", "GdipWarpPath", "hwnd", $hPathY, "hwnd", 0, "ptr", DllStructGetPtr($tWarpY), "int", 4, "float", 0, "float", 0, "float", $iSizeZ, "float", $iSizeY, "int", 0, "float", 0)
	DllCall($ghGDIPDll, "uint", "GdipWarpPath", "hwnd", $hPathZ, "hwnd", 0, "ptr", DllStructGetPtr($tWarpZ), "int", 4, "float", 0, "float", 0, "float", $iSizeX, "float", $iSizeY, "int", 0, "float", 0)

	DllCall($ghGDIPDll, "uint", "GdipDrawPath", "hwnd", $hContext, "hwnd", $hPen, "hwnd", $hPathX)
	DllCall($ghGDIPDll, "uint", "GdipDrawPath", "hwnd", $hContext, "hwnd", $hPen, "hwnd", $hPathY)

	Local $hMatrix = _GDIPlus_MatrixCreate()
	_GDIPlus_MatrixTranslate($hMatrix, $iWidth / 2, $iHeight / 2)
	_GDIPlus_MatrixRotate($hMatrix, 180)
	_GDIPlus_MatrixTranslate($hMatrix, -$iWidth / 2, -$iHeight / 2)

	DllCall($ghGDIPDll, "uint", "GdipTransformPath", "hwnd", $hPathX, "hwnd", $hMatrix)
	DllCall($ghGDIPDll, "uint", "GdipTransformPath", "hwnd", $hPathY, "hwnd", $hMatrix)

	_GDIPlus_MatrixDispose($hMatrix)

	DllCall($ghGDIPDll, "uint", "GdipDrawPath", "hwnd", $hContext, "hwnd", $hPen, "hwnd", $hPathX)
	DllCall($ghGDIPDll, "uint", "GdipDrawPath", "hwnd", $hContext, "hwnd", $hPen, "hwnd", $hPathY)
	DllCall($ghGDIPDll, "uint", "GdipDrawPath", "hwnd", $hContext, "hwnd", $hPen, "hwnd", $hPathZ)

	DllCall($ghGDIPDll, "uint", "GdipDeletePath", "hwnd", $hPathX)
	DllCall($ghGDIPDll, "uint", "GdipDeletePath", "hwnd", $hPathY)
	DllCall($ghGDIPDll, "uint", "GdipDeletePath", "hwnd", $hPathZ)
	_GDIPlus_PenDispose($hPen)
	_GDIPlus_GraphicsDispose($hContext)
	Return $hBitmap
EndFunc   ;==>_CreateBackGround



Func _CreateWarpPoints(ByRef $tWarpX, ByRef $tWarpY, ByRef $tWarpZ, $fWarp = 0.2)
	$tWarpX = DllStructCreate("float[8];")
	DllStructSetData($tWarpX, 1, $iWidth / 2 - $iWidth * $fWarp, 1)
	DllStructSetData($tWarpX, 1, $iHeight / 2 + $iHeight * $fWarp, 2)
	DllStructSetData($tWarpX, 1, $iWidth / 2 + $iWidth * $fWarp, 3)
	DllStructSetData($tWarpX, 1, $iHeight / 2 + $iHeight * $fWarp, 4)
	DllStructSetData($tWarpX, 1, 0, 5)
	DllStructSetData($tWarpX, 1, $iHeight, 6)
	DllStructSetData($tWarpX, 1, $iWidth, 7)
	DllStructSetData($tWarpX, 1, $iHeight, 8)

	$tWarpY = DllStructCreate("float[8];")
	DllStructSetData($tWarpY, 1, 0, 1)
	DllStructSetData($tWarpY, 1, 0, 2)
	DllStructSetData($tWarpY, 1, $iWidth / 2 - $iWidth * $fWarp, 3)
	DllStructSetData($tWarpY, 1, $iHeight / 2 - $iHeight * $fWarp, 4)
	DllStructSetData($tWarpY, 1, 0, 5)
	DllStructSetData($tWarpY, 1, $iHeight, 6)
	DllStructSetData($tWarpY, 1, $iWidth / 2 - $iWidth * $fWarp, 7)
	DllStructSetData($tWarpY, 1, $iHeight / 2 + $iHeight * $fWarp, 8)

	$tWarpZ = DllStructCreate("float[8];")
	DllStructSetData($tWarpZ, 1, $iWidth / 2 - $iWidth * $fWarp, 1)
	DllStructSetData($tWarpZ, 1, $iHeight / 2 - $iHeight * $fWarp, 2)
	DllStructSetData($tWarpZ, 1, $iWidth / 2 + $iWidth * $fWarp, 3)
	DllStructSetData($tWarpZ, 1, $iHeight / 2 - $iHeight * $fWarp, 4)
	DllStructSetData($tWarpZ, 1, $iWidth / 2 - $iWidth * $fWarp, 5)
	DllStructSetData($tWarpZ, 1, $iHeight / 2 + $iHeight * $fWarp, 6)
	DllStructSetData($tWarpZ, 1, $iWidth / 2 + $iWidth * $fWarp, 7)
	DllStructSetData($tWarpZ, 1, $iHeight / 2 + $iHeight * $fWarp, 8)
EndFunc   ;==>_CreateWarpPoints



Func _InitBalls($iMax)
	Local $aBall[$iMax + 1][11] = [[$iMax]]
	Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePath", "int", 0, "int*", 0)
	Local $hPath = $aResult[2]
	DllCall($ghGDIPDll, "uint", "GdipAddPathEllipse", "hwnd", $hPath, "float", 0, "float", 0, "float", $iMaxSize * 2, "float", $iMaxSize * 2)

	$aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePathGradientFromPath", "hwnd", $hPath, "int*", 0)
	Local $hBrush = $aResult[2]

	Local $tPoint = DllStructCreate("float;float")
	DllStructSetData($tPoint, 1, $iMaxSize * 0.6)
	DllStructSetData($tPoint, 2, $iMaxSize * 0.6)
	DllCall($ghGDIPDll, "uint", "GdipSetPathGradientCenterPoint", "hwnd", $hBrush, "ptr", DllStructGetPtr($tPoint))
	DllCall($ghGDIPDll, "uint", "GdipSetPathGradientCenterColor", "hwnd", $hBrush, "uint", 0xFFFFFFFF)
	DllCall($ghGDIPDll, "uint", "GdipSetPathGradientSigmaBlend", "hwnd", $hBrush, "float", 1, "float", 0.25)

	$aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePathGradientFromPath", "hwnd", $hPath, "int*", 0)
	Local $hBrush1 = $aResult[2]
	DllCall($ghGDIPDll, "uint", "GdipSetPathGradientCenterPoint", "hwnd", $hBrush1, "ptr", DllStructGetPtr($tPoint))
	DllCall($ghGDIPDll, "uint", "GdipSetPathGradientCenterColor", "hwnd", $hBrush1, "uint", 0x00000000)

	Local $tColors = DllStructCreate("uint")
	DllStructSetData($tColors, 1, 0xFF000000)
	DllCall($ghGDIPDll, "uint", "GdipSetPathGradientSurroundColorsWithCount", "hwnd", $hBrush1, "ptr", DllStructGetPtr($tColors), "int*", 1)

	Local $hPen = _GDIPlus_PenCreate(0xFF000000, 1)

	Local $hBitmap, $hContext
	For $i = 1 To $iMax
		$aBall[$i][6] = Random($iMinSize, $iMaxSize)
		$aBall[$i][0] = Random($aBall[$i][6], $iSizeX - $aBall[$i][6])
		$aBall[$i][1] = Random($aBall[$i][6], $iSizeY - $aBall[$i][6])
		$aBall[$i][2] = Random($aBall[$i][6], $iSizeZ - $aBall[$i][6])
		$aBall[$i][3] = Random($iMinSpeed, $iMaxSpeed)
		$aBall[$i][4] = Random($iMinSpeed, $iMaxSpeed)
		$aBall[$i][5] = Random($iMinSpeed, $iMaxSpeed)

		$hBitmap = _GDIPlus_BitmapCreateFromGraphics($iMaxSize * 2 + 1, $iMaxSize * 2 + 1, $hGraphics)
		$hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
		_GDIPlus_GraphicsSetSmoothingMode($hContext, 2)

		DllStructSetData($tColors, 1, $aColors[Random(1, $aColors[0], 1)])
		DllCall($ghGDIPDll, "uint", "GdipSetPathGradientSurroundColorsWithCount", "hwnd", $hBrush, "ptr", DllStructGetPtr($tColors), "int*", 1)

		_GDIPlus_GraphicsFillEllipse($hContext, 0, 0, $iMaxSize * 2, $iMaxSize * 2, $hBrush)
		_GDIPlus_GraphicsFillEllipse($hContext, 0, 0, $iMaxSize * 2, $iMaxSize * 2, $hBrush1)
		_GDIPlus_GraphicsDrawEllipse($hContext, 0, 0, $iMaxSize * 2, $iMaxSize * 2, $hPen)

		_GDIPlus_GraphicsDispose($hContext)
		$aBall[$i][10] = $hBitmap
	Next

	_GDIPlus_PenDispose($hPen)
	_GDIPlus_BrushDispose($hBrush)
	_GDIPlus_BrushDispose($hBrush1)
	Return $aBall
EndFunc   ;==>_InitBalls



Func WM_PAINT($hWnd, $uMsgm, $wParam, $lParam)
	_GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
	Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_PAINT


Func WM_ERASEBKGND($hWnd, $uMsgm, $wParam, $lParam)
	_GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
	Return True
EndFunc   ;==>WM_ERASEBKGND

Func _Exit()
	For $i = 1 To $aBall[0][0]
		_GDIPlus_BitmapDispose($aBall[$i][10])
	Next
	_GDIPlus_BitmapDispose($hBmpBG)
	_GDIPlus_PenDispose($hPen)
	_GDIPlus_BrushDispose($hBrush)
	_GDIPlus_GraphicsDispose($hGfxBuffer)
	_GDIPlus_BitmapDispose($hBmpBuffer)
	_GDIPlus_GraphicsDispose($hGraphics)
	_GDIPlus_Shutdown()
	Exit
EndFunc   ;==>_Exit