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

 我来答
数学与计算机编程
2017-05-21 · TA获得超过2159个赞
知道大有可为答主
回答量:2312
采纳率:80%
帮助的人:557万
展开全部
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
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
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
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
sbj518
2017-05-21 · TA获得超过4.4万个赞
知道大有可为答主
回答量:1.1万
采纳率:81%
帮助的人:5243万
展开全部
这个做过的。可以发给你看看。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式