;Idea taken from http://js1k.com/demo/304
;Ported to AutoIt by UEZ
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/sf /sv /om /cs=0 /cn=0
#AutoIt3Wrapper_Run_After=del /f /q "Tramp of Particles_Obfuscated.au3"
#AutoIt3Wrapper_Run_After=upx.exe --ultra-brute "%out%"
;~ #AutoIt3Wrapper_Run_After=upx.exe --best "%out%"
#include "QuickDraw.au3"
#include <GuiConstantsEx.au3>
Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)
Local $hWnd, $hGraphic, $hBitmap, $hBackbuffer, $hPen
Local $width = 640, $height = 480
Local $max_particle = 250
Local $aParticles[$max_particle + 1][5] ;x,y,vx,vy,color
Local $i, $x, $pi = ACos(-1), $pi180 = $pi / 180, $r, $g, $b
Local $gui_text = "Tramp of " & $max_particle & " Particles using QuickDraw   d•¿•b "
Local $fps = 0, $fps_maintimer, $fps_timer, $fps_diff
Local $ptrFont

For $i = 0 To UBound($aParticles) - 1
	$aParticles[$i][0] = Random(1, $width, 1)
	$aParticles[$i][1] = Random(1, $height, 1)
	$aParticles[$i][2] = 0
	$aParticles[$i][3] = 0
	$aParticles[$i][4] = 0xFFFFFFFF
;~ 	$r = 0x10 + Int(0xD0 * Abs(Sin($i * 3)))
;~ 	$g = 0x10 + Int(0xD0 * Abs(Cos($i * 2)))
;~ 	$b = 0x10 + Int(0xD0 * Abs(Sin($i * 1.25 / 2) + 1))
;~ 	$aParticles[$i][4] = "0xFF" & Hex($r, 2) & Hex($g, 2) & Hex($b, 2)
Next

_QuickDraw_Enable($gui_text, $width, $height, 0, 0, 0)

$ptrFont = _QuickDraw_CreateFont("Arial")

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

$fps_maintimer = TimerInit()
Do
	$fps_timer = TimerInit()
	_QuickDraw_ClearBuffer(0xFF000000)
	_QuickDraw_Text(1, 12, "FPS: " & StringFormat("%.2f", $fps), 16, $ptrFont, 2048, 0xFF8080FF)
	For $x = 0 To $max_particle
		$aParticles[$x][0] += $aParticles[$x][2]
		$aParticles[$x][1] += $aParticles[$x][3]
		If $aParticles[$x][0] < 0 Then $aParticles[$x][0] += $width
		If $aParticles[$x][0] > $width Then $aParticles[$x][0] -= $width
		If $aParticles[$x][1] < 0 Then $aParticles[$x][1] += $height
		If $aParticles[$x][1] > $height Then $aParticles[$x][1] -= $height
		$aParticles[$x][3] = Cos($aParticles[$x][0] * 0.02) + 0.25
		$aParticles[$x][2] = Sin($aParticles[$x][1] * 0.025) + 0.5
		If $aParticles[$x][0] > -1 And $aParticles[$x][0] < $width And $aParticles[$x][1] > -1 And $aParticles[$x][1] < $height Then _
			_QuickDraw_Point($aParticles[$x][0], $aParticles[$x][1], $aParticles[$x][4])
	Next
	$fps_diff = TimerDiff($fps_timer)
	If TimerDiff($fps_maintimer) > 999 Then ;calculate FPS
		$fps = Round(1000 / $fps_diff, 2)
		$fps_maintimer = TimerInit()
	EndIf
	_QuickDraw_SwapBuffers()
Until Not _QuickDraw_Running()

Func _Exit()
	$aParticles = 0
	_QuickDraw_FreeFont($ptrFont)
	_QuickDraw_Disable()
    Exit
EndFunc