#include <GDIPlus.au3>
#include "Bezier.au3"

Opt("GUIOnEventMode", 1)

Global $hGfx, $hBmp, $hBuffer, $pen, $brush
Global $bezierPointsX[7] = [50, 100, 400, 700, 200, 250, 630]
Global $bezierPointsY[7] = [50, 600,  50, 500, 500, 120, 200]
Global $bezierCurve = _GenerateBezier(6, $bezierPointsX, $bezierPointsY, 2000)
Global $hWnd = GUICreate("Bézier Curves", 800, 600, (@DesktopWidth/2) - 400, (@DesktopHeight/2) - 300)
GUISetOnEvent(-3, "_exit")
GUICtrlCreateGraphic(0, 0, 800, 600)
$hGfx = GUICtrlGetHandle(-1)
GUISetState()

_initGDIP()

While 1
	Sleep(1/60)
	_draw()
WEnd

Func _draw()
	_GDIPlus_GraphicsClear($hBuffer)
	For $i = 0 To 1999 Step 1
		_GDIPlus_GraphicsFillRect($hBuffer, $bezierCurve[$i][0], $bezierCurve[$i][1], 1, 1, $brush)
	Next
	_GDIPlus_GraphicsDrawImage($hGfx, $hBmp, 0, 0)
EndFunc

Func _initGDIP()
	_GDIPlus_Startup()
	$hGfx = _GDIPlus_GraphicsCreateFromHWND($hGfx)
	$hBmp = _GDIPlus_BitmapCreateFromGraphics(800, 600, $hGfx)
	$hBuffer = _GDIPlus_ImageGetGraphicsContext($hBmp)
	$pen = _GDIPlus_PenCreate(0xffffaa00)
	$brush = _GDIPlus_BrushCreateSolid(0xffffaa00)
EndFunc

Func _exit()
	_GDIPlus_PenDispose($pen)
	_GDIPlus_BrushDispose($brush)
	_GDIPlus_GraphicsDispose($hBuffer)
	_GDIPlus_BitmapDispose($hBmp)
    _GDIPlus_GraphicsDispose($hGfx)
    _GDIPlus_Shutdown()
	Exit
EndFunc