小弟初学VB,碰到一题目不解,求各位大哥大姐指导,请把代码回我参考一下(题目肯定简单,不花多少时间的,先在这里谢了)
题目:
程序启动后,一个蓝色的小圆围绕红色大圆沿椭圆轨迹运行(红色大圆须在屏幕中心),椭圆的参数方程为x=x1+HR*cos(a),y=y1+VR*sin(a),其中x1,y1为椭圆圆心坐标,HR,VR为水平和垂直半径,a为圆心角;
在窗体加入形状控件Shape1,Shape2分别作为红色大圆和蓝色小圆;
将定时器Timer1的时间间隔设置为1秒。 再次感谢
过几天就要交了
急啊 3个学分呢
题目:
程序启动后,一个蓝色的小圆围绕红色大圆沿椭圆轨迹运行(红色大圆须在屏幕中心),椭圆的参数方程为x=x1+HR*cos(a),y=y1+VR*sin(a),其中x1,y1为椭圆圆心坐标,HR,VR为水平和垂直半径,a为圆心角;
在窗体加入形状控件Shape1,Shape2分别作为红色大圆和蓝色小圆;
将定时器Timer1的时间间隔设置为1秒。 再次感谢
过几天就要交了
急啊 3个学分呢
Dim CurAngle As Single
Const BigRadius = 1000
Const SmallRadius = 200Private Sub Form_Load()
CurAngle = 0
Timer1.Interval = 100
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Me.Cls
Draw
End Sub
Private Sub Draw()
If CurAngle > (180 / 3.141592) * 360 Then
CurAngle = 0
End If
Circle (Me.ScaleWidth / 2, Me.ScaleHeight / 2), BigRadius, vbRed
Circle (Me.ScaleWidth / 2 + BigRadius * Cos(CurAngle), _
Me.ScaleHeight / 2 + BigRadius * Sin(CurAngle)), _
SmallRadius, vbBlue
CurAngle = CurAngle + 5 / (180 / 3.1415926)
End Sub
Option Explicit
Dim CAngle As Single
Const SR = 200
Const Hr = 500 '椭圆纵半径
Const Vr = 1000 '椭圆横半径Private Sub Form_Load()
CAngle = 0
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Me.Cls
DrawCircle
End Sub
Private Sub DrawCircle()
If CAngle > 360 Then
CAngle = 0
End If
Circle (Me.ScaleWidth / 2, Me.ScaleHeight / 2), Vr, vbRed, -2 * 3.1415926, 2 * 3.1415926, Hr / Vr
Circle (Me.ScaleWidth / 2 + Vr * Cos(CAngle), _
Me.ScaleHeight / 2 + (Vr * Sin(CAngle)) / 2), _
SR, vbBlue
CAngle = CAngle + 10 / (180 / 3.1415926)
End Sub