当前位置: 开源爱好者 » 编程教程 » VB教程 » 正文

VB模拟星空流星雨-基于随机数的生成

VB练习使用随机数的应用,学习随机数的用法,生成流星,模拟出流量雨特效,可制作成屏保,相关代码:

VERSION 5.00
Begin VB.Form Form1 
   BackColor       =   &H00000000&
   Caption         =   "使用VB随机数模拟星空流星雨"
   ClientHeight    =   7935
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   9180
   FillColor       =   &H0000FFFF&
   ForeColor       =   &H00FFFF80&
   LinkTopic       =   "Form1"
   ScaleHeight     =   7935
   ScaleWidth      =   9180
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton cmdQuit 
      Caption         =   "退出"
      Height          =   375
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   975
   End
   Begin VB.Timer Timer1 
      Interval        =   1
      Left            =   120
      Top             =   12480
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'VB运用随机函数生成夜空繁星,模拟流星雨,学习随机数用法
Dim X(100), Y(100), pace(100), size(100) As Integer
Private Sub cmdQuit_Click()
Unload Me
End Sub
Private Sub Form_Activate()
Randomize
For I = 1 To 100
X1 = Int(Form1.Width * Rnd)
Y1 = Int(Form1.Height * Rnd)
pace1 = Int(500 - (Int(Rnd * 499)))
size1 = 25 * Rnd
X(I) = X1
Y(I) = Y1
pace(I) = pace1
size(I) = size1
Next
End Sub
Private Sub Timer1_Timer()
For I = 1 To 100
Circle (X(I), Y(I)), size(I), BackColor
Y(I) = Y(I) + pace(I)
If Y(I) >= Form1.Height Then Y(I) = 0: X(I) = Int(Form1.Width * Rnd)
Circle (X(I), Y(I)), size(I)
Next
End Sub

CopyRight 2015© 开源爱好者 All Rights Reserved 豫ICP备16030607号 隐私声明 网站地图