疑惑,下述代码是如何实现模拟下雪的?
我从网上找了一个VB模拟下雪的代码,能够实现模拟下雪。
但我看不懂具体代码是什么意思,望高手赐教~~~~~
Dim Snow(1000, 2), Amounty As Integer
Private Sub Form_Load()
Form1.Show
DoEvents
Randomize: Amounty = 325
For J = 1 To Amounty
Snow(J, 0) = Int(Rnd * Form1.Width)
Snow(J, 1) = Int(Rnd * Form1.Height)
Snow(J, 2) = 10 + (Rnd * 20)
Next J
Do While Not (DoEvents = 0)
For LS = 1 To 10
For I = 1 To Amounty
OldX = Snow(I, 0): OldY = Snow(I, 1): Snow(I, 1) = Snow(I, 1) + Snow(I, 2)
If Snow(I, 1) > Form1.Height Then Snow(I, 1) = 0: Snow(I, 2) = 5 + (Rnd * 30): Snow(I, 0) = Int(Rnd * Form1.Width): OldX = 0: OldY = 0
Coloury = 8 * (Snow(I, 2) - 10): Coloury = 60 + Coloury: PSet (OldX, OldY), QBColor(0): PSet (Snow(I, 0), Snow(I, 1)), RGB(Coloury, Coloury, Coloury)
Next I
Next LS
'Label1.Refre
Loop
End
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
End
End Sub
[解决办法]
你找的这个程序也模拟得太那个了点,看了运行效果,本来都不想写了
就当打短工挣5分吧
Dim Snow(1000, 2), Amounty As Integer
Private Sub Form_Load()
Form1.Show
DoEvents
Randomize: Amounty = 325
For J = 1 To Amounty '初始化雪花点
Snow(J, 0) = Int(Rnd * Form1.Width) '横坐标
Snow(J, 1) = Int(Rnd * Form1.Height) '纵坐标
Snow(J, 2) = 10 + (Rnd * 20) '速度
Next J
Do While Not (DoEvents = 0) '一直下
'For LS = 1 To 10 '几乎没有任何意义的垃圾循环
For I = 1 To Amounty '遍历所有雪花
OldX = Snow(I, 0): OldY = Snow(I, 1): Snow(I, 1) = Snow(I, 1) + Snow(I, 2) '根据速度下落
'如果掉到地上,重新初始化这朵雪花
If Snow(I, 1) > Form1.Height Then Snow(I, 1) = 0: Snow(I, 2) = 5 + (Rnd * 30): Snow(I, 0) = Int(Rnd * Form1.Width): OldX = 0: OldY = 0
'画新雪花,并把经过的地方涂黑(汗......起码把QBColor(0)换成Form1.BackColor也好点吧)
Coloury = 8 * (Snow(I, 2) - 10): Coloury = 60 + Coloury: PSet (OldX, OldY), QBColor(0): PSet (Snow(I, 0), Snow(I, 1)), RGB(Coloury, Coloury, Coloury)
Next I
'Next LS
'Label1.Refre
Loop
End
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
End
End Sub
------解决方案--------------------
RGB(Coloury, Coloury, Coloury)
是让雪有远近感,白色,灰白。。。懂??