求助高手,用VB设计一个程序,实现一个圆绕椭圆轨迹运动的动画效果
2个回答
展开全部
这样就可以了,楼上的子函数M() 没有用到
Dim pi As Double
Dim runTime As Double
Dim a As Single, b As Single
Dim cntX As Single, cntY As Single
Dim r As Single
Private WithEvents Timer1 As Timer
Dim tX As Single, tY As Single
Dim tStep As Single
Private Sub Form_Load()
Me.ScaleMode = 3
Me.AutoRedraw = True
pi = Atn(1)
Set Timer1 = Controls.Add("vb.timer", "Timer1")
a = 50 '椭圆长轴
b = 30 '椭圆短轴
cntX = 100 '中心坐标X
cntY = 60 '中心坐标Y
r = 10 '圆半径
Timer1.Interval = 50 '运动间隔(毫秒)
tStep = pi / 10 '角度步长
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
runTime = runTime + 1
Dim Arg As Double
Arg = runTime * tStep
tX = cntX + a * Cos(Arg)
tY = cntY + b * Sin(Arg)
Me.Cls
Me.DrawStyle = 2
Me.Circle (cntX, cntY), a, , , , b / a
Me.DrawStyle = 0
Me.Circle (tX, tY), r
End Sub
Dim pi As Double
Dim runTime As Double
Dim a As Single, b As Single
Dim cntX As Single, cntY As Single
Dim r As Single
Private WithEvents Timer1 As Timer
Dim tX As Single, tY As Single
Dim tStep As Single
Private Sub Form_Load()
Me.ScaleMode = 3
Me.AutoRedraw = True
pi = Atn(1)
Set Timer1 = Controls.Add("vb.timer", "Timer1")
a = 50 '椭圆长轴
b = 30 '椭圆短轴
cntX = 100 '中心坐标X
cntY = 60 '中心坐标Y
r = 10 '圆半径
Timer1.Interval = 50 '运动间隔(毫秒)
tStep = pi / 10 '角度步长
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
runTime = runTime + 1
Dim Arg As Double
Arg = runTime * tStep
tX = cntX + a * Cos(Arg)
tY = cntY + b * Sin(Arg)
Me.Cls
Me.DrawStyle = 2
Me.Circle (cntX, cntY), a, , , , b / a
Me.DrawStyle = 0
Me.Circle (tX, tY), r
End Sub
展开全部
直接新建窗体,将代码贴入即可
Dim pi As Double
Dim runTime As Double
Dim a As Single, b As Single
Dim cntX As Single, cntY As Single
Dim r As Single
Private WithEvents Timer1 As Timer
Dim tX As Single, tY As Single
Dim tStep As Single
Private Sub Form_Load()
Me.ScaleMode = 3
Me.AutoRedraw = True
pi = Atn(1)
Set Timer1 = Controls.Add("vb.timer", "Timer1")
a = 50 '椭圆长轴
b = 30 '椭圆短轴
cntX = 100 '中心坐标X
cntY = 60 '中心坐标Y
r = 10 '圆半径
Timer1.Interval = 50 '运动间隔(毫秒)
tStep = pi / 10 '角度步长
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
runTime = runTime + 1
Dim Arg As Double
Arg = runTime * tStep
tX = cntX + a * Cos(Arg)
tY = cntY + b * Sin(Arg)
Me.Cls
Me.DrawStyle = 2
Me.Circle (cntX, cntY), a, , , , b / a
Me.DrawStyle = 0
Me.Circle (tX, tY), r
End Sub
Private Function M(ByVal X As Single, ByVal Y As Single)
M = Sqr(X ^ 2 + Y ^ 2)
End Function
Dim pi As Double
Dim runTime As Double
Dim a As Single, b As Single
Dim cntX As Single, cntY As Single
Dim r As Single
Private WithEvents Timer1 As Timer
Dim tX As Single, tY As Single
Dim tStep As Single
Private Sub Form_Load()
Me.ScaleMode = 3
Me.AutoRedraw = True
pi = Atn(1)
Set Timer1 = Controls.Add("vb.timer", "Timer1")
a = 50 '椭圆长轴
b = 30 '椭圆短轴
cntX = 100 '中心坐标X
cntY = 60 '中心坐标Y
r = 10 '圆半径
Timer1.Interval = 50 '运动间隔(毫秒)
tStep = pi / 10 '角度步长
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
runTime = runTime + 1
Dim Arg As Double
Arg = runTime * tStep
tX = cntX + a * Cos(Arg)
tY = cntY + b * Sin(Arg)
Me.Cls
Me.DrawStyle = 2
Me.Circle (cntX, cntY), a, , , , b / a
Me.DrawStyle = 0
Me.Circle (tX, tY), r
End Sub
Private Function M(ByVal X As Single, ByVal Y As Single)
M = Sqr(X ^ 2 + Y ^ 2)
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询