完成一个“行星”的程序设计,要求:
程序启动后,一个蓝色的小圆围绕红色大圆沿椭圆轨迹运行,椭圆的参数方程为x=x1+HR*COS(a),y=y1+VR*sin(a),其中x1、y1为椭圆圆心坐标,HR、VR为水平和垂直半径,a为圆心角;
在窗体加入形状控件Shape1、Shape2分别作为红色大圆和蓝色小圆;
将定时器Tiner1的间隔设置为1秒。
(必须是最大化,且大圆的圆心在中点,大圆不动,小圆角度变化)

解决方案 »

  1.   

    保存成 form1.frmVERSION 5.00
    Begin VB.Form Form1 
       Caption         =   "Form1"
       ClientHeight    =   3195
       ClientLeft      =   60
       ClientTop       =   345
       ClientWidth     =   4680
       LinkTopic       =   "Form1"
       ScaleHeight     =   3195
       ScaleWidth      =   4680
       StartUpPosition =   2  '屏幕中心
       WindowState     =   2  'Maximized
       Begin VB.Timer Timer1 
          Interval        =   1000
          Left            =   960
          Top             =   2280
       End
       Begin VB.Shape Shape2 
          BorderColor     =   &H00FF0000&
          Height          =   495
          Left            =   2280
          Shape           =   3  'Circle
          Top             =   1440
          Width           =   615
       End
       Begin VB.Shape Shape1 
          BorderColor     =   &H000000FF&
          Height          =   975
          Left            =   840
          Shape           =   3  'Circle
          Top             =   840
          Width           =   1095
       End
    End
    Attribute VB_Name = "Form1"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = False
    Attribute VB_PredeclaredId = True
    Attribute VB_Exposed = False
    Option Explicit
    Dim a As SinglePrivate Sub Form_Load()
    a = 5
    End SubPrivate Sub Form_Resize()
    Shape1.Left = (Me.Width - Shape1.Width) / 2
    Shape1.Top = (Me.Height - Shape1.Height) / 2
    End SubPrivate Sub Timer1_Timer()
    Dim x As Single
    Dim y As Single
    Dim HR As Single
    Dim VR As Single
    HR = 5000
    VR = 3000
    a = a + 0.1
    x = (Shape1.Left + Shape1.Width / 2) + HR * Cos(a)
    y = (Shape1.Top + Shape1.Height / 2) + VR * Sin(a)
    Shape2.Left = x + Shape2.Width / 2
    Shape2.Top = y + Shape2.Height / 2
    End Sub