Option Explicit
Dim x(1 To 100) As Single, y(1 To 100) As Single, sudux(1 To 100) As Integer, pianyix(1 To 100) As Integer, suduy(1 To 100) As Integer, daxiao(1 To 100) As Integer, yanse(1 To 100) As Integer, i As Integer
Dim WithEvents TimCD As Timer
Private Sub Form_Load()
Set TimCD = Me.Controls.Add(“VB.Timer”, “TimCD”)
TimCD.Interval = 20
For i = 1 To 100
xin i
Next
End Sub
Private Sub Timcd_Timer()
For i = 1 To 100
If y(i) > Me.Height Then xin i
Me.DrawWidth = daxiao(i)
PSet (x(i), y(i)), Me.BackColor
If pianyix(i) > x(i) Then
x(i) = x(i) + sudux(i)
If x(i) >= pianyix(i) Then pianyix(i) = IIf(Int(Rnd * 2) = 1, x(i) + Int(Rnd * 501 + 500), x(i) - Int(Rnd * 501 + 500))
Else
x(i) = x(i) - sudux(i)
If x(i) <= pianyix(i) Then pianyix(i) = IIf(Int(Rnd * 2) = 1, x(i) + Int(Rnd * 501 + 500), x(i) - Int(Rnd * 501 + 500))
End If
y(i) = y(i) + suduy(i)
PSet (x(i), y(i)), QBColor(yanse(i))
Next
End Sub
Sub xin(ByVal i As Integer)
x(i) = Int(Rnd * Me.Width + 1)
y(i) = 0
sudux(i) = Int(Rnd * 41 + 10)
pianyix(i) = IIf(Int(Rnd * 2) = 1, x(i) + Int(Rnd * 2001 + 2000), x(i) - Int(Rnd * 2001 + 2000))
suduy(i) = Int(Rnd * 101 + 50)
daxiao(i) = Int(Rnd * 11 + 5)
yanse(i) = Int(Rnd * 16)
End Sub