Advertisement
logix

asdParticles

Dec 15th, 2012
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 3.66 KB | None | 0 0
  1. #include <GDIPlus.au3>
  2. #include <Array.au3>
  3.  
  4. _GDIPlus_Startup()
  5.  
  6. Global $Speed = 10
  7. Global $minLife = 500
  8. Global $maxLife = 2000
  9. Global $maxSpeed = 10.6
  10. Global $GUIWidth = 800
  11. Global $GUIHeight = 600
  12. Global $BackgroundColor = 0x40000000
  13. Global $PartN = InputBox("Numero particelle", "Inserisci il numero di particelle: ", 100)
  14. Global $FPS, $FPSTimer, $FPSCounter
  15. Dim $Particles[$PartN][9]
  16.  
  17. For $i = 0 To $PartN - 1
  18.     $Particles[$i][0] = $GUIWidth / 2
  19.     $Particles[$i][1] = $GUIHeight / 2
  20.     $Particles[$i][2] = Random(-$maxSpeed, $maxSpeed)
  21.     $Particles[$i][3] = Random(-$maxSpeed, $maxSpeed)
  22.     $Particles[$i][4] = 1
  23.     $Particles[$i][5] = 1
  24.     $Particles[$i][6] = 0xFF000000 + Random(0x0000FF, 0xFFFFFF, 1)
  25.     $Particles[$i][7] = TimerInit()
  26.     $Particles[$i][8] = Random($minLife, $maxLife, 1)
  27. Next
  28.  
  29. Opt("GuiOnEventMode", 1)
  30.  
  31. $GUI = GUICreate("asdParticles", $GUIWidth, $GUIHeight)
  32. GUISetBkColor(0x00000, $GUI)
  33. GUISetOnEvent(-3, "GUIExit")
  34.  
  35. $Graphics = _GDIPlus_GraphicsCreateFromHWND($GUI)
  36. $BufferBMP = _GDIPlus_BitmapCreateFromGraphics($GUIWidth, $GUIHeight, $Graphics)
  37. $Buffer = _GDIPlus_ImageGetGraphicsContext($BufferBMP)
  38.  
  39. _GDIPlus_GraphicsSetSmoothingMode($Buffer, 2)
  40.  
  41. GUISetState(@SW_SHOW, $GUI)
  42.  
  43. $FPSTimer = TimerInit()
  44.  
  45. AdlibRegister("ShowFPS", 10)
  46. While 1
  47.     _GDIPlus_GraphicsClear($Buffer, $BackgroundColor)
  48.     $Brush = _GDIPlus_BrushCreateSolid()
  49.     For $i = 0 To $PartN - 1
  50.         $MousePos = GUIGetCursorInfo($GUI)
  51.  
  52.         If IsArray($MousePos) Then
  53.             $distX = Abs($MousePos[0] - $Particles[$i][0])
  54.             $distY = Abs($MousePos[1] - $Particles[$i][1])
  55.             $distD = Sqrt($distX ^ 2 + $distY ^ 2)
  56.             If $distD > 100 Then
  57.                 $Particles[$i][4] = Random(2,3,1)
  58.                 $Particles[$i][5] = Random(2,3,1)
  59.             Else
  60.                 $Particles[$i][4] = Random(1,2,1)
  61.                 $Particles[$i][5] = Random(1,2,1)
  62.             EndIf
  63.         EndIf
  64.  
  65.         If $Particles[$i][7] > TimerInit() Then ContinueLoop
  66.         If TimerDiff($Particles[$i][7]) > $Particles[$i][8] Then
  67.             $Particles[$i][0] = $GUIWidth / 2
  68.             $Particles[$i][1] = $GUIHeight / 2
  69.             $Particles[$i][2] = Random(-$maxSpeed, $maxSpeed)
  70.             $Particles[$i][3] = Random(-$maxSpeed, $maxSpeed)
  71.             $Particles[$i][4] = 1
  72.             $Particles[$i][5] = 1
  73.             $Particles[$i][7] = TimerInit()+$maxLife*40
  74.             $Particles[$i][8] = Random($minLife, $maxLife, 1)
  75.             ContinueLoop
  76.         EndIf
  77.         _GDIPlus_BrushSetSolidColor($Brush, $Particles[$i][6])
  78.  
  79.         If ($Particles[$i][0] + $Particles[$i][2]) > $GUIWidth Then
  80.             $Particles[$i][0] = $GUIWidth - ($Particles[$i][2] - ($GUIWidth - $Particles[$i][0]))
  81.             $Particles[$i][2] *= -1
  82.         ElseIf ($Particles[$i][0] + $Particles[$i][2]) < 0 Then
  83.             $Particles[$i][0] = -($Particles[$i][2] + $Particles[$i][0])
  84.             $Particles[$i][2] *= -1
  85.         EndIf
  86.  
  87.         If ($Particles[$i][1] + $Particles[$i][3]) > $GUIHeight Then
  88.             $Particles[$i][1] = $GUIHeight - ($Particles[$i][3] - ($GUIHeight - $Particles[$i][1]))
  89.             $Particles[$i][3] *= -1
  90.         ElseIf ($Particles[$i][1] + $Particles[$i][2]) < 0 Then
  91.             $Particles[$i][1] = -($Particles[$i][2] + $Particles[$i][1])
  92.             $Particles[$i][3] *= -1
  93.         EndIf
  94.  
  95.         $Particles[$i][2] *= 0.98
  96.         $Particles[$i][3] *= 0.98
  97.  
  98.  
  99.         $Particles[$i][0] += $Particles[$i][2]
  100.         $Particles[$i][1] += $Particles[$i][3]
  101.  
  102.         _GDIPlus_GraphicsFillEllipse($Buffer, $Particles[$i][0], $Particles[$i][1], $Particles[$i][4], $Particles[$i][5], $Brush)
  103.     Next
  104.  
  105.     _GDIPlus_GraphicsDrawImageRect($Graphics, $BufferBMP, 0, 0, $GUIWidth, $GUIHeight)
  106.     FPSCounter()
  107.     Sleep(20)
  108. WEnd
  109.  
  110. Func GUIExit()
  111.     _GDIPlus_Shutdown()
  112.     Exit
  113. EndFunc
  114.  
  115. Func FPSCounter()
  116.     If TimerDiff($FPSTimer) > 1000 Then
  117.         $FPSTimer = TimerInit()
  118.         $FPS = $FPSCounter
  119.         $FPSCounter = 0
  120.     EndIf
  121.     $FPSCounter += 1
  122. EndFunc
  123.  
  124. Func ShowFPS()
  125.     ToolTip($FPS&" fps")
  126. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement