Advertisement
logix

asdParticles 2

Dec 16th, 2012
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 4.76 KB | None | 0 0
  1. #include <GDIPlus.au3>
  2. #include <Array.au3>
  3.  
  4. _GDIPlus_Startup()
  5.  
  6. Global $minLife = 500
  7. Global $maxLife = 5000
  8. Global $maxSpeed = 15
  9. Global $GUIWidth = 800
  10. Global $GUIHeight = 600
  11. Global $BackgroundColor = 0x10010101
  12. Global $PartN = InputBox("Numero particelle", "Inserisci il numero di particelle: ", 200)
  13. Global $FPS, $FPSTimer, $FPSCounter
  14. Dim $Particles[$PartN][9]
  15.  
  16. For $i = 0 To $PartN - 1
  17.     NewParticle($i, True)
  18. Next
  19.  
  20. Opt("GuiOnEventMode", 1)
  21.  
  22. $GUI = GUICreate("asdParticles", $GUIWidth, $GUIHeight)
  23. GUISetBkColor(0x00000, $GUI)
  24. GUISetOnEvent(-3, "GUIExit")
  25.  
  26. $Graphics = _GDIPlus_GraphicsCreateFromHWND($GUI)
  27. $BufferBMP = _GDIPlus_BitmapCreateFromGraphics($GUIWidth, $GUIHeight, $Graphics)
  28. $Buffer = _GDIPlus_ImageGetGraphicsContext($BufferBMP)
  29.  
  30. _GDIPlus_GraphicsSetSmoothingMode($Buffer, 2)
  31.  
  32. GUISetState(@SW_SHOW, $GUI)
  33.  
  34. $FPSTimer = TimerInit()
  35.  
  36. AdlibRegister("Update", 25)
  37. AdlibRegister("Draw", 25)
  38. AdlibRegister("ShowFPS", 1000)
  39.  
  40. While 1
  41.     Sleep(20)
  42. WEnd
  43.  
  44. Func Draw()
  45.     _GDIPlus_GraphicsClear($Buffer, $BackgroundColor)
  46.     $Brush = _GDIPlus_BrushCreateSolid()
  47.     For $i = 0 To $PartN - 1
  48.         _GDIPlus_BrushSetSolidColor($Brush, $Particles[$i][6])
  49.         _GDIPlus_GraphicsFillEllipse($Buffer, $Particles[$i][0], $Particles[$i][1], $Particles[$i][4], $Particles[$i][5], $Brush)
  50.     Next
  51.     _GDIPlus_BrushDispose($Brush)
  52.     _GDIPlus_GraphicsDrawImageRect($Graphics, $BufferBMP, 0, 0, $GUIWidth, $GUIHeight)
  53.     FPSCounter()
  54. EndFunc   ;==>Draw
  55.  
  56.  
  57. Func Update()
  58.     $nearMouseSize = 3.5
  59.     $farMouseSize = 2.5
  60.  
  61.     $MousePos = GUIGetCursorInfo($GUI)
  62.     If $MousePos[2] Then $clickColor = newRandomColor()
  63.  
  64.     Local $xComp = 0, $yComp = 0
  65.     For $i = 0 To $PartN - 1
  66.  
  67.         If IsArray($MousePos) Then
  68.  
  69.             If $MousePos[2] = 1 Then
  70.                 If $Particles[$i][2] < 20 Then $Particles[$i][2] *= 1.2
  71.                 If $Particles[$i][3] < 20 Then $Particles[$i][3] *= 1.2
  72.                 $Particles[$i][4] = $nearMouseSize
  73.                 $Particles[$i][5] = $nearMouseSize
  74.                 $Particles[$i][6] = $clickColor
  75.             EndIf
  76.  
  77.             $dh = $MousePos[0] - $Particles[$i][0]
  78.             $dv = $MousePos[1] - $Particles[$i][1]
  79.             $distX = Abs($dh)
  80.             $distY = Abs($dv)
  81.             $distD = Sqrt($distX ^ 2 + $distY ^ 2)
  82.             If $distD > 150 Then
  83.                 $Particles[$i][4] = $farMouseSize ; Random(3, 4, 1)
  84.                 $Particles[$i][5] = $farMouseSize ; Random(3, 4, 1)
  85.             Else
  86.                 $Particles[$i][4] = $nearMouseSize ; Random(1, 2, 1)
  87.                 $Particles[$i][5] = $nearMouseSize ; Random(1, 2, 1)
  88.             EndIf
  89.         EndIf
  90.  
  91.         If $Particles[$i][7] > TimerInit() Then ContinueLoop
  92.         If TimerDiff($Particles[$i][7]) > $Particles[$i][8] Then
  93.             NewParticle($i)
  94.             ContinueLoop
  95.         EndIf
  96.  
  97.         If ($Particles[$i][0] + $Particles[$i][2]) > $GUIWidth Then
  98.             $Particles[$i][0] = $GUIWidth - ($Particles[$i][2] - ($GUIWidth - $Particles[$i][0]))
  99.             $Particles[$i][2] *= -1
  100.         ElseIf ($Particles[$i][0] + $Particles[$i][2]) < 0 Then
  101.             $Particles[$i][0] = -($Particles[$i][2] + $Particles[$i][0])
  102.             $Particles[$i][2] *= -1
  103.         EndIf
  104.  
  105.         If ($Particles[$i][1] + $Particles[$i][3]) > $GUIHeight Then
  106.             $Particles[$i][1] = $GUIHeight - ($Particles[$i][3] - ($GUIHeight - $Particles[$i][1]))
  107.             $Particles[$i][3] *= -1
  108.         ElseIf ($Particles[$i][1] + $Particles[$i][2]) < 0 Then
  109.             $Particles[$i][1] = -($Particles[$i][2] + $Particles[$i][1])
  110.             $Particles[$i][3] *= -1
  111.         EndIf
  112.  
  113.         If $xComp > 0 Then $Particles[$i][2] -= $xComp
  114.         If $yComp > 0 Then $Particles[$i][3] -= $yComp
  115.         $Particles[$i][2] *= 0.98
  116.         $Particles[$i][3] *= 0.98
  117.  
  118.         $Particles[$i][0] += $Particles[$i][2]
  119.         $Particles[$i][1] += $Particles[$i][3]
  120.     Next
  121. EndFunc   ;==>Update
  122.  
  123. Func GUIExit()
  124.     _GDIPlus_Shutdown()
  125.     Exit
  126. EndFunc   ;==>GUIExit
  127.  
  128. Func FPSCounter()
  129.     If TimerDiff($FPSTimer) > 1000 Then
  130.         $FPSTimer = TimerInit()
  131.         $FPS = $FPSCounter
  132.         $FPSCounter = 0
  133.     EndIf
  134.     $FPSCounter += 1
  135. EndFunc   ;==>FPSCounter
  136.  
  137. Func ShowFPS()
  138.     WinSetTitle(WinGetTitle($GUI), "", "asdParticles - " & $FPS & " fps")
  139. EndFunc   ;==>ShowFPS
  140.  
  141. Func _DebugWrite($txt, $line = @ScriptLineNumber)
  142.     $txt = StringReplace($txt, @CRLF, @LF)
  143.     $txt = StringReplace($txt, @CR, @LF)
  144.     $split = StringSplit($txt, @LF)
  145.     For $x = 1 To $split[0]
  146.         If $split[$x] <> "" Then ConsoleWrite(@LF & "===>" & @HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC & " - PID:" & @AutoItPID & " - " & $line & @TAB & "|" & $split[$x])
  147.     Next
  148. EndFunc   ;==>_DebugWrite
  149.  
  150. Func NewParticle($i, $newcolor = True)
  151.     $Particles[$i][0] = $GUIWidth / 2
  152.     $Particles[$i][1] = $GUIHeight / 2
  153.     $Particles[$i][2] = Random(-$maxSpeed, $maxSpeed)
  154.     $Particles[$i][3] = Random(-$maxSpeed, $maxSpeed)
  155.     $Particles[$i][4] = 1
  156.     $Particles[$i][5] = 1
  157.     If $newcolor Then $Particles[$i][6] = newRandomColor()
  158.     $Particles[$i][7] = TimerInit()
  159.     $Particles[$i][8] = Random($minLife, $maxLife, 1)
  160. EndFunc   ;==>NewParticle
  161.  
  162. Func newRandomColor()
  163.     Return 0xFF000000 + Random(0x0000FF, 0xFFFFFF, 1)
  164. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement