Advertisement
logix

asdParticles 3

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