求助高手,用VB设计一个程序,实现一个圆绕椭圆轨迹运动的动画效果

 我来答
djrm_yb
2008-08-18 · TA获得超过1927个赞
知道小有建树答主
回答量:1035
采纳率:100%
帮助的人:782万
展开全部
这样就可以了,楼上的子函数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
zfcsl
2008-08-18 · TA获得超过203个赞
知道小有建树答主
回答量:254
采纳率:0%
帮助的人:364万
展开全部
直接新建窗体,将代码贴入即可

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
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式