Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GDIPlus.au3>
- #include <GUIConstantsEx.au3>
- Global Const $width = 960
- Global Const $height = $width / 16 * 9
- Global $g_bPaused = False
- Global $hGui
- Global Const $title = "Sorting - Alan72104"
- GlobaL $hGraphics
- Global Const $bgColorARGB = 0xFF000000
- Global $frameBuffer
- Global $hFrameBuffer
- Global $brushRed
- Global $brushWhite
- Global $hTimerFrame
- Global $nTimerFrame
- Global $hTimerDraw
- Global $smoothedFrameTime
- Global Const $tps = 60
- Global Const $frameTimeSmoothingRatio = 0.3
- Global Const $arrayLength = 500
- Global $array[$arrayLength]
- HotKeySet("{F6}", "TogglePause")
- HotKeySet("{F7}", "Terminate")
- Func CreateArray()
- For $i = 0 To $arrayLength - 1
- $array[$i] = Random(0, $height, 1)
- Next
- EndFunc
- Func Update()
- Local Static $i =1
- ; For $i = 1 To $arrayLength - 1
- If $i < $arrayLength Then
- For $j = 0 To $arrayLength - $i - 1
- If $array[$j] > $array[$j + 1] Then
- Swap($array[$j], $array[$j + 1])
- EndIf
- Next
- $i += 1
- EndIf
- ; Next
- EndFunc
- Func Draw()
- _GDIPlus_GraphicsClear($hFrameBuffer, $bgColorARGB)
- For $i = 0 To $arrayLength - 1
- _GDIPlus_GraphicsFillRect($hFrameBuffer, 0 + $i * $width / $arrayLength, $height - $array[$i], _
- $width / $arrayLength, $array[$i], $brushWhite)
- Next
- EndFunc
- Func FrameBufferTransfer()
- _GDIPlus_GraphicsDrawImage($hGraphics, $frameBuffer, 0, 0)
- EndFunc
- Func Main()
- _DebugOn()
- _GDIPlus_Startup()
- $hGui = GUICreate($title, $width, $height)
- ; $hGui = GUICreate($title, $width, $height, Default, Default, Default, $WS_EX_TOPMOST)
- GUISetBkColor($bgColorARGB - 0xFF000000, $hGui)
- $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
- $frameBuffer = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphics)
- $hFrameBuffer = _GDIPlus_ImageGetGraphicsContext($frameBuffer)
- $brushRed = _GDIPlus_BrushCreateSolid(0xFFFF0000)
- $brushWhite = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
- CreateArray()
- GUISetState(@SW_SHOW)
- While 1
- $hTimerFrame = TimerInit()
- Update()
- If TimerDiff($hTimerDraw) >= 1000 / $tps Then
- Draw()
- FrameBufferTransfer()
- $hTimerDraw = TimerInit()
- EndIf
- $nTimerFrame = TimerDiff($hTimerFrame)
- $smoothedFrameTime = ($smoothedFrameTime * (1 - $frameTimeSmoothingRatio)) + $nTimerFrame * $frameTimeSmoothingRatio
- Switch GUIGetMsg()
- Case $GUI_EVENT_CLOSE
- Terminate()
- EndSwitch
- WEnd
- EndFunc
- Main()
- Func Swap(ByRef $a, ByRef $b)
- Local $t = $a
- $a = $b
- $b = $t
- EndFunc
- Func GdiPlusClose()
- _GDIPlus_BrushDispose($brushRed)
- _GDIPlus_BrushDispose($brushWhite)
- _GDIPlus_BitmapDispose($frameBuffer)
- _GDIPlus_GraphicsDispose($hGraphics)
- _GDIPlus_Shutdown()
- EndFunc
- Func Terminate()
- GdiPlusClose()
- GUIDelete($hGui)
- Exit 0
- EndFunc
- Func TogglePause()
- $g_bPaused = Not $g_bPaused
- While $g_bPaused
- Sleep(500)
- ToolTip('Script is "Paused"', @desktopWidth / 2, @desktopHeight / 2, Default, Default, $TIP_CENTER)
- WEnd
- ToolTip("")
- EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement