VB实现粒子效果
Private Declare Function SetPixel Lib “gdi32” (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
Private Type PARTICLE
x As Single
y As Single
S As Long
FX As Single
ZL As Single
Show As Boolean
End Type
Dim A(1000) As PARTICLE
Private WithEvents Counter As Timer
Private Sub Form_Load()
Set Counter = Controls.Add(“VB.Timer”, “Counter”)
Counter.Interval = 1
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
For i = 0 To 2
addlz x, y
Next i
End Sub
Private Sub Counter_Timer()
Me.Cls
For i = 0 To 1000
If A(i).Show = True Then
A(i).x = A(i).x + A(i).FX
A(i).y = A(i).y + A(i).ZL
A(i).S = A(i).S - 1
If A(i).S < 0 Then A(i).Show = False
SetPixel Me.hdc, A(i).x, A(i).y, RGB(0, 0, 0)
End If
Next i
Me.Refresh
End Sub
Private Function addlz(x As Single, y As Single)
For i = 0 To 1000
If A(i).Show = False Then
A(i).x = x
A(i).y = y
A(i).FX = Rnd * 2 - 1
A(i).ZL = Rnd * 2 - 1
A(i).S = 50 + Rnd * 50
A(i).Show = True
Exit For
End If
Next i
End Function