对于下雪的景象大家可能都不陌生,我们还是用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 End If 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 Loop End End Sub 编写窗体的鼠标按下代码: Private Sub Form_MouseDown(Button As Integer,Shift As Integer, X As Single, Y As Single) unload me End Sub 运行上面的小程序,就可以看到漫天的雪花在缓缓落下,地面上还会有积雪!鼠标单击可结
|