📄 雪花飘飘.frm
字号:
VERSION 5.00
Begin VB.Form Form1
BackColor = &H8000000C&
Caption = "模拟下雪"
ClientHeight = 5430
ClientLeft = 60
ClientTop = 345
ClientWidth = 6750
DrawWidth = 2
LinkTopic = "Form1"
ScaleHeight = 5430
ScaleWidth = 6750
StartUpPosition = 3 '窗口缺省
Begin VB.Timer Timer1
Interval = 20
Left = 2160
Top = 4200
End
Begin VB.CommandButton Command1
Caption = "退出"
Height = 375
Left = 5880
TabIndex = 0
Top = 5040
Width = 855
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' 雪花飘飘---星空模拟之改进版,可以用鼠标直接指定飘的方向和速度
' 随机数,数组,定时器,IF语句的使用。
' 曹新国,2004-3-24修改
'
'
Option Explicit
Const NumPies As Integer = 200 '雪花的总片数
Dim X1, X2, Y1, Y2, DX, DY
Dim X%(NumPies), Y%(NumPies), spd%(NumPies), siz%(NumPies)
Private Sub Command1_Click()
Unload Me
End Sub
Private Sub Form_load()
Dim i As Integer
Randomize Val(Right(Time, 2)) '是与Rnd配套使用的一条语句,它可以生成一个随机数。
For i = 1 To NumPies
X(i) = Int(Form1.Width * Rnd) '位置
Y(i) = Int(Form1.Height * Rnd)
spd(i) = 50 + 50 * Rnd() '速度
siz(i) = 10 * Rnd + spd(i) * 0.1 '大小
Next
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
X1 = X
Y1 = Y
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
X2 = X
Y2 = Y
DX = (X2 - X1) / 10
DY = (Y2 - Y1) / 10
End Sub
Private Sub Timer1_Timer()
Dim i As Integer
Dim w%, h%
w = Me.Width
h = Me.Height
For i = 1 To NumPies
'去掉旧的
Circle (X(i), Y(i)), siz(i), BackColor
Y(i) = Y(i) + spd(i) + DY
X(i) = X(i) - Rnd * 80 + DX
'滑出底部处理
If Y(i) > h Then
Y(i) = 0
X(i) = Int(w * Rnd)
End If
'滑出底部处理
If Y(i) < 0 Then
Y(i) = h * Rnd
X(i) = Int(w * Rnd)
End If
'飘出左边处理
If X(i) < 0 Then
X(i) = w * Rnd
Y(i) = Int(h * Rnd)
End If
'飘出右边处理
If X(i) > w Then
X(i) = 0
Y(i) = Int(h * Rnd)
End If
'在新位置画出新的
Circle (X(i), Y(i)), siz(i), vbWhite
Next
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -