VB按三角形轨迹运动
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/17 14:22:11
VB按三角形轨迹运动
VB按三角形轨迹运动
VB按三角形轨迹运动
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