作业帮 > 综合 > 作业

vb课程设计,怎么做一个小球沿着正弦曲线运动的程序?

来源:学生作业帮 编辑:搜搜做题作业网作业帮 分类:综合作业 时间:2024/05/07 13:30:47
vb课程设计,怎么做一个小球沿着正弦曲线运动的程序?
一个实心的小红球沿SIN(X)的曲线匀速运动.要求速度值和曲线区间可由用户在界面自行设置,运动过程可随时停止和启动.
vb课程设计,怎么做一个小球沿着正弦曲线运动的程序?
改个txt复制后改名为Form1.frm
VERSION 5.00
Begin VB.Form Form1
AutoRedraw = -1 'True
Caption = "Form1"
ClientHeight = 4545
ClientLeft = 120
ClientTop = 450
ClientWidth = 6465
LinkTopic = "Form1"
ScaleHeight = 303
ScaleMode = 3 'Pixel
ScaleWidth = 431
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox TxtFle
Height = 270
Index = 1
Left = 3960
TabIndex = 3
Text = "2"
Top = 2520
Width = 735
End
Begin VB.TextBox TxtFle
Height = 270
Index = 0
Left = 1800
TabIndex = 2
Text = "0"
Top = 2520
Width = 735
End
Begin VB.HScrollBar HScroll1
Height = 375
Left = 2520
Max = 300
TabIndex = 1
Top = 2880
Width = 1335
End
Begin VB.Timer Timer1
Enabled = 0 'False
Interval = 30
Left = 1080
Tag = "0"
Top = 3360
End
Begin VB.CommandButton Command1
Caption = "开始"
Height = 375
Left = 600
TabIndex = 0
Top = 2880
Width = 855
End
Begin VB.Label Label3
Caption = "速度"
Height = 375
Left = 1800
TabIndex = 6
Top = 3000
Width = 615
End
Begin VB.Label Label2
Caption = "最大PI单位"
Height = 255
Left = 2640
TabIndex = 5
Top = 2520
Width = 1095
End
Begin VB.Label Label1
Caption = "最小PI单位"
Height = 255
Left = 600
TabIndex = 4
Top = 2520
Width = 1095
End
Begin VB.Shape Shape1
BackStyle = 1 'Opaque
Height = 255
Left = 2040
Shape = 3 'Circle
Top = 1560
Width = 135
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim SpaceTop As Integer
Dim StepB As Double
Const PI = 3.1415926
Dim SFlag As Boolean
Dim MaxSpeed As Integer
Dim MaxFle As Double
Dim MinFle As Double
Dim Bl As Integer
Private Sub Command1_Click()
If Command1.Caption = "开始" Then
Timer1.Enabled = True
Command1.Caption = "停止"
Else
Timer1.Enabled = False
Command1.Caption = "开始"
End If
End Sub
Private Sub Form_Load()
Bl = 40
SpaceTop = 40
MaxFle = 2 * PI
MinFle = 0
StepB = PI / 100
MaxSpeed = 51
HScroll1.Max = MaxSpeed - 1
HScroll1.Min = 0
HScroll1.Value = 40
Timer1.Interval = MaxSpeed - HScroll1.Value
End Sub
Private Sub HScroll1_Change()
On Error Resume Next
Timer1.Interval = MaxSpeed - HScroll1.Value
End Sub
Private Sub Timer1_Timer()
Timer1.Enabled = False
Me.CurrentX = Timer1.Tag * Bl
Me.CurrentY = SpaceTop + Sin(Timer1.Tag) * Bl
Me.Print "."
If Timer1.Tag = MinFle Then
Shape1.Left = Timer1.Tag * Bl - Shape1.Width / 2
Shape1.Top = SpaceTop + Sin(Timer1.Tag) * Bl - Shape1.Width / 2
If SFlag = False Then
Timer1.Tag = Timer1.Tag + StepB
Else
Timer1.Tag = Timer1.Tag - StepB
End If
Else
If SFlag = False Then
SFlag = True
Timer1.Tag = MaxFle
Else
SFlag = False
Timer1.Tag = MinFle
End If
End If
Timer1.Enabled = True
End Sub
Private Sub TxtFle_Change(Index As Integer)
MaxFle = Val(TxtFle(1)) * PI
MinFle = TxtFle(0) * PI
End Sub
其他的自己完善一下吧 下班喽