vb课程设计,怎么做一个小球沿着正弦曲线运动的程序
4个回答
展开全部
Const π As Single = 3.1415926
Dim x As Single
Private Sub Command1_Click()
Timer1.Interval = 1
End Sub
Private Sub Form_Load()
Picture1.Left = 50
Picture1.Top = 50
Picture1.Width = Me.Width - 220
Picture1.Height = Me.Height - 1000
Picture1.Scale (-2 * π, 1.2)-(2 * π, -1.2)
Picture1.AutoRedraw = True
Picture1.DrawWidth = 1
Picture1.Line (-2 * π, 0)-(2 * π, 0), vbBlue
Picture1.Line (0, -1.2)-(0, 1.2), vbBlue
Picture1.BackColor = vbBlack
Picture1.FillColor = vbRed
Picture1.FillStyle = 0
x = -2 * π
Picture1.Line (-2 * π, 0)-(2 * π, 0), vbBlue
Picture1.Line (0, -1.2)-(0, 1.2), vbBlue
For i = -2 * π To 2 * π Step 0.001
Picture1.PSet (i, Sin(i)), vbGreen
Next i
End Sub
Private Sub Timer1_Timer()
Picture1.Cls
For i = -2 * π To 2 * π Step 0.001
Picture1.PSet (i, Sin(i)), vbGreen
Next i
Picture1.Line (-2 * π, 0)-(2 * π, 0), vbBlue
Picture1.Line (0, -1.2)-(0, 1.2), vbBlue
Picture1.Circle (x, Sin(x)), 0.2, vbRed
x = x + 0.03
If x >= 2 * π Then x = -2 * π
End Sub
2017-05-24
展开全部
改个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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2017-05-22
展开全部
改个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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个做过的。可以发给你看看。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询