Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As LongOption ExplicitPrivate Const MaxExpRad = 50 Private Const Gravity = 0.09Private Type Color R As Integer G As Integer B As Integer Rpace As Integer Gpace As Integer Bpace As Integer End TypePrivate Type Firework EX(MaxExpRad) As Single EY(MaxExpRad) As Single OldEx(MaxExpRad) As Single OldEy(MaxExpRad) As Single EXD(MaxExpRad) As Single EYD(MaxExpRad) As Single Col As Color x As Integer y As Integer End TypeDim MyFW(1 To 10) As FireworkPrivate Sub Command1_Click() Randomize Timer Dim Num As Integer, n As Integer Dim i As Integer
Picture1.Cls n = UBound(MyFW) For Num = 1 To n MyFW(Num).Col.R = Int(Rnd * 100) + 155 MyFW(Num).Col.Rpace = Int(Rnd * 3) + 3 MyFW(Num).Col.G = Int(Rnd * 100) + 155 MyFW(Num).Col.Gpace = Int(Rnd * 3) + 3 MyFW(Num).Col.B = Int(Rnd * 100) + 155 MyFW(Num).Col.Bpace = Int(Rnd * 3) + 3 MyFW(Num).x = Int(Rnd * Picture1.ScaleWidth) + 1 MyFW(Num).y = Int(Rnd * Picture1.ScaleHeight) + 1 For i = 1 To MaxExpRad MyFW(Num).EX(i) = MyFW(Num).x MyFW(Num).EY(i) = MyFW(Num).y MyFW(Num).EXD(i) = Rnd - Rnd MyFW(Num).EYD(i) = Rnd - Rnd Next i Next Num
Do For Num = 1 To n For i = 1 To MaxExpRad MyFW(Num).OldEx(i) = MyFW(Num).EX(i) MyFW(Num).OldEy(i) = MyFW(Num).EY(i) SetPixel Picture1.hdc, MyFW(Num).OldEx(i), MyFW(Num).OldEy(i), vbBlack MyFW(Num).EX(i) = MyFW(Num).EX(i) + MyFW(Num).EXD(i) MyFW(Num).EY(i) = MyFW(Num).EY(i) + MyFW(Num).EYD(i) MyFW(Num).EYD(i) = MyFW(Num).EYD(i) + Gravity * Rnd SetPixel Picture1.hdc, MyFW(Num).EX(i), MyFW(Num).EY(i), RGB(MyFW(Num).Col.R, MyFW(Num).Col.G, MyFW(Num).Col.B) DoEvents Next i MyFW(Num).Col.R = MyFW(Num).Col.R - MyFW(Num).Col.Rpace MyFW(Num).Col.G = MyFW(Num).Col.G - MyFW(Num).Col.Gpace MyFW(Num).Col.B = MyFW(Num).Col.B - MyFW(Num).Col.Bpace If MyFW(Num).Col.R < 0 Then MyFW(Num).Col.R = 0 If MyFW(Num).Col.G < 0 Then MyFW(Num).Col.G = 0 If MyFW(Num).Col.B < 0 Then MyFW(Num).Col.B = 0 If RGB(MyFW(Num).Col.R, MyFW(Num).Col.G, MyFW(Num).Col.B) = 0 Then MyFW(Num).Col.R = Int(Rnd * 100) + 155 MyFW(Num).Col.Rpace = Int(Rnd * 4) + 3 MyFW(Num).Col.G = Int(Rnd * 100) + 155 MyFW(Num).Col.Gpace = Int(Rnd * 4) + 3 MyFW(Num).Col.B = Int(Rnd * 100) + 155 MyFW(Num).Col.Bpace = Int(Rnd * 4) + 3 MyFW(Num).x = Int(Rnd * Picture1.ScaleWidth) + 1 MyFW(Num).y = Int(Rnd * Picture1.ScaleHeight) + 1 For i = 1 To MaxExpRad MyFW(Num).EX(i) = MyFW(Num).x MyFW(Num).EY(i) = MyFW(Num).y MyFW(Num).EXD(i) = Rnd - Rnd MyFW(Num).EYD(i) = Rnd - Rnd Next i End If Next Num Loop End SubPrivate Sub Form_Unload(Cancel As Integer) Unload Me End End Sub
MSTOP不要跟他计较!
你用 vc做你想要得,可能比vb實際些
Private Const Gravity = 0.09Private Type Color
R As Integer
G As Integer
B As Integer
Rpace As Integer
Gpace As Integer
Bpace As Integer
End TypePrivate Type Firework
EX(MaxExpRad) As Single
EY(MaxExpRad) As Single
OldEx(MaxExpRad) As Single
OldEy(MaxExpRad) As Single
EXD(MaxExpRad) As Single
EYD(MaxExpRad) As Single
Col As Color
x As Integer
y As Integer
End TypeDim MyFW(1 To 10) As FireworkPrivate Sub Command1_Click()
Randomize Timer
Dim Num As Integer, n As Integer
Dim i As Integer
Picture1.Cls
n = UBound(MyFW)
For Num = 1 To n
MyFW(Num).Col.R = Int(Rnd * 100) + 155
MyFW(Num).Col.Rpace = Int(Rnd * 3) + 3
MyFW(Num).Col.G = Int(Rnd * 100) + 155
MyFW(Num).Col.Gpace = Int(Rnd * 3) + 3
MyFW(Num).Col.B = Int(Rnd * 100) + 155
MyFW(Num).Col.Bpace = Int(Rnd * 3) + 3
MyFW(Num).x = Int(Rnd * Picture1.ScaleWidth) + 1
MyFW(Num).y = Int(Rnd * Picture1.ScaleHeight) + 1
For i = 1 To MaxExpRad
MyFW(Num).EX(i) = MyFW(Num).x
MyFW(Num).EY(i) = MyFW(Num).y
MyFW(Num).EXD(i) = Rnd - Rnd
MyFW(Num).EYD(i) = Rnd - Rnd
Next i
Next Num
Do
For Num = 1 To n
For i = 1 To MaxExpRad
MyFW(Num).OldEx(i) = MyFW(Num).EX(i)
MyFW(Num).OldEy(i) = MyFW(Num).EY(i)
SetPixel Picture1.hdc, MyFW(Num).OldEx(i), MyFW(Num).OldEy(i), vbBlack
MyFW(Num).EX(i) = MyFW(Num).EX(i) + MyFW(Num).EXD(i)
MyFW(Num).EY(i) = MyFW(Num).EY(i) + MyFW(Num).EYD(i)
MyFW(Num).EYD(i) = MyFW(Num).EYD(i) + Gravity * Rnd
SetPixel Picture1.hdc, MyFW(Num).EX(i), MyFW(Num).EY(i), RGB(MyFW(Num).Col.R, MyFW(Num).Col.G, MyFW(Num).Col.B)
DoEvents
Next i
MyFW(Num).Col.R = MyFW(Num).Col.R - MyFW(Num).Col.Rpace
MyFW(Num).Col.G = MyFW(Num).Col.G - MyFW(Num).Col.Gpace
MyFW(Num).Col.B = MyFW(Num).Col.B - MyFW(Num).Col.Bpace
If MyFW(Num).Col.R < 0 Then MyFW(Num).Col.R = 0
If MyFW(Num).Col.G < 0 Then MyFW(Num).Col.G = 0
If MyFW(Num).Col.B < 0 Then MyFW(Num).Col.B = 0
If RGB(MyFW(Num).Col.R, MyFW(Num).Col.G, MyFW(Num).Col.B) = 0 Then
MyFW(Num).Col.R = Int(Rnd * 100) + 155
MyFW(Num).Col.Rpace = Int(Rnd * 4) + 3
MyFW(Num).Col.G = Int(Rnd * 100) + 155
MyFW(Num).Col.Gpace = Int(Rnd * 4) + 3
MyFW(Num).Col.B = Int(Rnd * 100) + 155
MyFW(Num).Col.Bpace = Int(Rnd * 4) + 3
MyFW(Num).x = Int(Rnd * Picture1.ScaleWidth) + 1
MyFW(Num).y = Int(Rnd * Picture1.ScaleHeight) + 1
For i = 1 To MaxExpRad
MyFW(Num).EX(i) = MyFW(Num).x
MyFW(Num).EY(i) = MyFW(Num).y
MyFW(Num).EXD(i) = Rnd - Rnd
MyFW(Num).EYD(i) = Rnd - Rnd
Next i
End If
Next Num
Loop
End SubPrivate Sub Form_Unload(Cancel As Integer)
Unload Me
End
End Sub