问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

vb怎样做礼花绽放的效果,求程序代码。

发布网友 发布时间:2023-10-30 06:03

我来回答

2个回答

热心网友 时间:2024-11-19 07:53

用记事本生成以下四个文件,再到VB中新建一个工程,加入这4个文件,就可以看到礼花绽放效果。
CExplosion.cls文件内容:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "CExplosion"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
' CExplosion - Basically a collection of CFrags.

Option Explicit

Private m_Col As Collection
Private m_hDC As Long

' X and Y are the start position.
' How many frags do you want?
Public Sub Setup(x As Single, y As Single, FragCount As Integer, Gravity As Single, hDC As Long)
Dim i As Integer
Dim frag As CFrag
Dim Direction As Single, vel As Single

Set m_Col = New Collection

For i = 1 To FragCount
Set frag = New CFrag

Direction = Rnd * (2 * pi)
vel = (Rnd * 20) + 10

frag.Init x, y, Direction, vel, Gravity

m_Col.Add frag
Next i

m_hDC = hDC
End Sub

' Move and draw the frags.
Public Function Move() As Boolean
Dim frag As CFrag
Dim DeadCount As Integer

For Each frag In m_Col
With frag
If Not .Move Then DeadCount = DeadCount + 1
Ellipse m_hDC, .x - 2, .y - 2, .x + 1, .y + 1
End With
Next frag

Move = Not (DeadCount = m_Col.Count)
End Function

CFrag.cls文件内容:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "CFrag"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
' CFrag - Represents a flying object with velocity and direction.
' From this it can work out a path of co-ordinates.
' Basic trigonometry is used.

Option Explicit

Private m_Direction As Single ' In Radians.
Private m_Velocity As Single
Private m_Gravity As Single ' Make it fall towards bottom of screen.

Private m_X As Single, m_Y As Single

' Setup the object.
Public Sub Init(XStart As Single, YStart As Single, Direction As Single, Velocity As Single, Gravity As Single)
m_Direction = Direction
m_Velocity = Velocity
m_Gravity = Gravity
m_X = XStart
m_Y = YStart
End Sub

' Move the object along its path.
Public Function Move() As Boolean
m_Velocity = m_Velocity - 1 ' Decrease speed.

If m_Velocity > 0 Then
m_X = m_X + (m_Velocity * Cos(m_Direction))
m_Y = m_Y + (m_Velocity * Sin(m_Direction)) + m_Gravity
Move = True
' Else it has stopped.
End If
End Function

Public Property Get x() As Single
x = m_X
End Property

Public Property Get y() As Single
y = m_Y
End Property

CTrail.cls文件内容:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "CTrail"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
' CTrail - Display a trail of dots for a set length.

Option Explicit

Private m_Direction As Single
Private m_Length As Integer
Private m_hDC As Long
Private m_X As Single, m_Y As Single

Public Sub Init(x As Single, y As Single, Direction As Single, Length As Integer, hDC As Long)
m_X = x
m_Y = y
m_Direction = Direction
m_Length = Length
m_hDC = hDC
End Sub

Public Function Move() As Boolean
If m_Length > 0 Then
m_Length = m_Length - 1

m_X = m_X + 10 * Cos(m_Direction)
m_Y = m_Y + 10 * Sin(m_Direction)

Sparkle m_X, m_Y
Move = True
Else
Move = False
End If
End Function

' Draw a random splatter of dots about x,y.
Private Sub Sparkle(x As Single, y As Single)
Dim i As Byte
Dim nX As Single, nY As Single
Dim angle As Single

For i = 1 To (Rnd * 5) + 3
angle = Rnd * (2 * pi)
nX = x + (3 * Cos(angle))
nY = y + (3 * Sin(angle))
Ellipse m_hDC, nX - 1, nY - 1, nX + 1, nY + 1
Next i
End Sub

Public Property Get x() As Single
x = m_X
End Property

Public Property Get y() As Single
y = m_Y
End Property

frmExplode.frm文件内容:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
VERSION 5.00
Begin VB.Form frmExplode
Caption = "Form1"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
FillStyle = 0 'Solid
LinkTopic = "Form1"
ScaleHeight = 213
ScaleMode = 3 'Pixel
ScaleWidth = 312
StartUpPosition = 3 'Windows Default
WindowState = 2 'Maximized
Begin VB.CommandButton cmdExit
Caption = "E&xit"
Height = 375
Left = 3000
TabIndex = 2
Top = 2520
Width = 1215
End
Begin VB.CommandButton cmdClear
Caption = "&Clear"
Height = 375
Left = 1680
TabIndex = 1
Top = 2520
Width = 1215
End
Begin VB.PictureBox Picture1
BackColor = &H00000000&
FillStyle = 0 'Solid
Height = 2295
Left = 120
ScaleHeight = 149
ScaleMode = 3 'Pixel
ScaleWidth = 301
TabIndex = 0
Top = 120
Width = 4575
End
Begin VB.Timer tmrMove
Enabled = 0 'False
Interval = 10
Left = 4080
Top = 120
End
End
Attribute VB_Name = "frmExplode"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Explosion - Simulate fireworks on your PC. Just click on the black box!

Option Explicit

Private explosion As CExplosion
Private trail As CTrail
Private bExplode As Boolean

Private Sub cmdClear_Click()
Picture1.Cls
End Sub

Private Sub cmdExit_Click()
Unload Me
End Sub

Private Sub Form_Resize()
' Keep everything looking good.
Dim h As Single
On Error Resume Next

h = ScaleHeight - cmdClear.Height

Picture1.Move 0, 0, ScaleWidth, h
cmdClear.Move 0, h
cmdExit.Move 0 + cmdClear.Width, h
End Sub

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Not tmrMove.Enabled Then
' Create a new trail...

' Choose a color from a list.
Picture1.ForeColor = Choose(Int(Rnd * 5) + 1, vbRed, vbWhite, vbCyan, vbGreen, vbYellow)
Picture1.FillColor = Me.ForeColor

Set trail = New CTrail
' Choose random direction from 255 to 344
trail.Init x, y, Radians(Int(Rnd * 90) + 225), Int(Rnd * 30) + 20, Picture1.hDC

tmrMove.Enabled = True ' Timer will handle drawing.
End If
End Sub

Private Sub tmrMove_Timer()
' Note that the move functions also draw.
' They return false when the object no longer is moving.

If trail.Move = False And bExplode = False Then
' The trail has stopped so explode.
bExplode = True
Set explosion = New CExplosion
explosion.Setup trail.x, trail.y, Int(Rnd * 30) + 10, 9, Picture1.hDC
End If

If bExplode Then
If explosion.Move = False Then
' Reset for a new explosion!
tmrMove.Enabled = False
bExplode = False
End If
End If
End Sub

' Simple function to convert degrees to radians.
Private Function Radians(sngDegrees As Single) As Single
Radians = sngDegrees * pi / 180
End Function

modStuff.bas文件内容:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Attribute VB_Name = "modStuff"
Option Explicit

' To get Pi type "? 4 * Atn(1)" in the immediate window,
' copy the result into code!
Public Const pi = 3.14159265358979

Public Declare Function Ellipse Lib "gdi32" (ByVal hDC As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long

热心网友 时间:2024-11-19 07:53

朋友我先问你问题,为什么我的提问不能上传了
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
李卓彬工作简历 林少明工作简历 广东工业职业技术学院怎么样 郑德涛任职简历 唐新桂个人简历 土地入股的定义 ups快递客服电话24小时 贷款记录在征信保留几年? 安徽徽商城有限公司公司简介 安徽省徽商集团新能源股份有限公司基本情况 oppo手机可以登陆两个吗8 OPPO手机怎么能登陆两个1 OPPO手机能同时登陆两个吗?33 oppo手机可以登陆两个吗?8 食用盐的溶解度是多少128 OPPO手机怎么能登陆两个1 OPPO手机能同时登陆两个吗?33 oppo手机可以登陆两个吗?8 电脑硬盘剩余内存与实际不符。。。。1 为什么电脑的安装内存和可用内存不一样大呀?1 地衣究竟是什么?9 央视一号演播大厅在哪里?是在中央电视台新址还是旧址?1 ...他一个人看。设定指定人可以看。现在他把我删除了。他还能看我空间... 求一篇事件营销或营销类外文文献和翻译 淘宝帐号怎么样才可以在阿里巴巴开店?8 涂鸦用的,喷颜色的瓶子叫什么?2 想问一下有一款洗面奶,在瓶子的右方好像有个化学式的那款洗面奶... 喷面漆时,怎么样喷能减少桔皮的现象 有人晓得谜色瓶子上那个菘蓝是啥啊? 苹果手机怎么查登录过哪些 你好我想求你帮我一下vb,做出烟花效果,带有字的,实在不行,... 有一个vb的exe文件及dll文件(烟花效果),请问我在另一... VB截取图片和烟花效果 用VB设计一个很简单的程序 OPPO手机怎么样用原来的手机号再申请一个? 怎样判断一个女人是不是在骗你?1 室内设计的人适合做建筑设计吗? 防雨布,雨篷布属于商标中哪一类1 遮篷,帐篷注册商标属于哪一类? 有没有杨洋的粉丝 可以帮个忙吗?帮我写一篇杨洋的作文或者情话 字数... 有关于杨洋和粉丝的暖心瞬间吗? 怎样辨别干香菇的好坏,37 请问从湖州长兴到台州路桥需要多少时间? 怎么选干香菇?如何分辨好差?84 如何鉴别干蘑菇好坏1 oppo手机可以登陆两个吗?8 OPPO手机能同时登陆两个吗?33 知道的说说三星笔记本电脑怎么关机2 汽车美容装潢和汽车钣金喷漆哪个好啊,就是哪个好找工作工资能高...5 汽车美容赚钱还是钣金喷漆赚钱?