天体运行程序代码.doc
《天体运行程序代码.doc》由会员分享,可在线阅读,更多相关《天体运行程序代码.doc(21页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、以下是窗体代码,在 VB6.0 调试通过:一、必须在引用中勾选:OLE Automatuon,否则 Img As StdPicture 语句会出错二、需在窗体放置以下 4 个控件,所有控件不用设置任何属性,均采用默认设置: Picture1,Picture2,Timer1,Command1(注意:在属性窗口将 Command1 的 Index 属性设置为 0)三、为窗体添加一个名为 mFast 的菜单,再为 mFast 添加一个名为 mmFast 的下级子菜单,并将 mmFast 的索引设置为 0。 即:mmFast 是以序号 0 开头的菜单数组控件的第一个。Dim ctD() As tyD,
2、 ctDs As Long, ctB() As Long, ctCenter As Long, ct3D As BooleanDim ctBi As Single, ctV As Single, ctBW As Long, ctSeeJ As Long, ctTrack As BooleanDim ctSeeBi As Single, ctSet As MenuSet, ctShowXX As Boolean, ctColorXX As BooleanDim ctP180 As Single, ctP90 As Single, ctP270 As Single, ctP360 As Singl
3、eDim ctSmall() As tySmall, ctSmalls As Long, ctX() As tyX, ctXs As Long, ctSize As Long定义表示星星的数据类型Private Type tyX x As Single y As Single r As Long t As Long Se As LongEnd Type定义表示天体的数据类型Private Type tyD Ji As Long天体级别 Cap As String天体名称 r As Long天体半径(像素,下同) a As Single轨道:横半径 b As Single轨道:纵半径 C As
4、Single轨道:焦点 e As Single轨道:偏心率 Dip As Single轨道:倾角 IsHui As Boolean 是否彗星 IsSmall As Boolean 是否小行星 Father As Long父天体序号:轨道焦点上的天体 Se As Long颜色 V As Single运行角速度 Jiao As Single某时刻的与父天体连线角度 x As Single天体当前坐标 y As Single xUp As Single上一时刻坐标 yUp As Single Visible As Boolean 是否显示:球体 ShowCap As Boolean 是否显示:标题
5、GuiDao As Boolean是否显示:轨道 GuiJi As Boolean是否显示:轨迹 Img As StdPicture天体 3D 图像 LineFu As Boolean与父天体的中心连线End Type定义小行星类型Private Type tySmall a As Single轨道:横半径 b As Single轨道:纵半径 Jiao As SingleEnd TypeEnum MenuSet以下为 选项菜单 标示 ms_Size = -11设置字体大小 ms_RunStop = -10 开始/暂停 ms_3D = -93D 立体图像 ms_ColorXX = -8是否显彩色
6、星星 ms_ShowXX = -7是否显示闪烁的星星 ms_DefSet = -6默认设置 ms_Track = -5轨迹:显示/隐藏以下为 菜单全选、全不选 ms_Wei = -4 ms_Xing = -3 ms_All = -2 ms_NoAll = -1以下为 按钮 标示 ms_Step = 0步进,下一位置 ms_UnRun后退 ms_Opt显示选项菜单 ms_Center参照系 ms_Visible天体:显示/隐藏 ms_ShowCap天体名称 ms_GuiDao轨道 ms_GuiJi轨迹 ms_LineFu与父天体的中心连线 ms_Bi缩放比 ms_V速度 ms_SeeJ视角End
7、 EnumPrivate Declare Function GdiTransparentBlt Lib gdi32 (ByVal hdc1 As Long, ByVal X1 As Long, ByVal y1 As Long, ByVal W1 As Long, ByVal H1 As Long, ByVal Hdc2 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal W2 As Long, ByVal H2 As Long, ByVal Color As Long) As LongPrivate Sub Form_Load() Me.Sc
8、aleMode = 3: Me.Caption = 太阳系行星运行演示 mFast.Visible = False: ctP180 = 3.1415926 ctP90 = ctP180 * 0.5: ctP360 = ctP180 * 2: ctP270 = ctP90 * 3 Timer1.Interval = 25: Timer1.Enabled = True Call Init窗体大小为屏幕的 3/4,居中 Me.Move Screen.Width * 0.1, Screen.Height * 0.1, Screen.Width * 0.8, Screen.Height * 0.8End
9、 SubPrivate Sub Form_Resize() Dim I As Long, L As Single, t As Single, H As Single, H1 As Single, W As Single设置控件位置 H1 = Me.TextHeight(A): L = H1 * 0.3: t = L L = 3 For I = 0 To Command1.Count - 1 W = Me.TextWidth(Command1(I).Caption & ab) Command1(I).Move L, t, W, H1 * 2 L = L + W + 3 Next t = t *
10、2 + Command1(0).Height: H = Me.ScaleHeight - t If H 0 Then Picture1.Move 0, t, Me.ScaleWidth, H将 Picture1 的中心设置为坐标原点 Picture1.ScaleMode = 3 Picture1.ScaleLeft = -Picture1.ScaleWidth * 0.5 Picture1.ScaleTop = -Picture1.ScaleHeight * 0.5 Picture1.Cls Call Run1End SubPrivate Sub Init()初始化天体参数 Dim I As
11、Long, K As Long, S As Long ctBW = 0 40 四周边界空白区,仅用于调试。调试完毕应设为 0 。调试代码* Picture1.AutoRedraw = True: Picture1.BackColor = &H180000 Picture1.ScaleMode = 3 Picture2.BorderStyle = 0: Picture2.ScaleMode = 3 Picture2.AutoRedraw = True: Picture2.Visible = False Picture2.BackColor = Picture1.BackColor ctSize
12、= 9 ctCenter = 0: ctBi = 1: ctV = 1 参照系(位于中心的天体),缩放比列,速度 ctSeeJ = 30: ctSeeBi = ctSeeJ / 90 视点角度,视角比 ctTrack = False 默认:不显示运动轨迹(不是轨道) ct3D = True默认:3D 立体图像 ctShowXX = True 默认:显示闪烁的星星 Call RndXX初始闪烁的星星添加按钮 KjCls Command1: Command1(0).BackColor = Me.BackColor KjAdd Command1, 选项(&O), ms_Opt, 设置选项 KjAdd
13、 Command1, 进(&W), ms_Step, 步进,运行到下一位置 KjAdd Command1, 退(&T), ms_UnRun, 步进,后退到上一位置 KjAdd Command1, 参照系(&C), ms_Center, 设置参照系(位于中心的天体) KjAdd Command1, 天体(&X), ms_Visible, 天体:显示/隐藏 KjAdd Command1, 名称(&M), ms_ShowCap, 天体名称:显示/隐藏 KjAdd Command1, 轨道(&D), ms_GuiDao, 天体运行轨道:显示/隐藏 KjAdd Command1, 轨迹(&J), ms_
14、GuiJi, 运动轨迹,选中“选项-显示运动轨迹”时有效 KjAdd Command1, 连线(&L), ms_LineFu, 与父天体的中心连线,同时显示对应天体时有效 KjAdd Command1, 速度(&V), ms_V, 设置速度 KjAdd Command1, 视角(&S), ms_SeeJ, 设置视点角度 KjAdd Command1, 缩放(&F), ms_Bi, 设置缩放比列添加天体(演示比列状态下),半径以 100 像素为标准参数依次是:名称,父天体名称,天体半径,轨道长半轴,轨道偏心率,运动角速度,轨道倾角,天体颜色,初始角度,彗星否 ctDs = -1: ReDim c
15、tD(0 To 0) AddCircle 太阳, , 22, 2, 0, 1.44, , RGB(230, 180, 0) AddCircle 水星, , 5, 0.5, 0.206, 5.45, 7.001, &H999999 AddCircle 金星, , 9, 0.8, 0.007, 3.24, 3.394, &H55AAAA AddCircle 地球, , 10, 1.2, 0.017, 1.81, , RGB(0, 0, 255) AddCircle 月亮, 地球, 4, 0.2, 0, 10.8, , &H333333 ctD(CapToNum(月亮).IsSmall = True
16、 调试代码* AddCircle 嫦娥1号, 月亮, 2, 0.06, 0, 21.6, , &HCCCCCC AddCircle 火星, , 6, 1.8, 0.093, 0.91, 1.851, &H1155FF AddCircle 火卫1, 火星, 3, 0.1, 0, 15, , &H555500, 10 AddCircle 火卫2, 火星, 3, 0.15, 0, 17, , &H5555DD, 200 AddCircle 小行星, , 6, 2.4, 0.093, 0.7, 0, &H666666 小行星轨道倾角多少? ctD(CapToNum(小行星).IsSmall = Tru
17、e AddCircle 木星, , 16, 3, 0.0483, 0.54, 1.308, &H776655 AddCircle 木卫1, 木星, 2, 0.25, 0, 9, , &H883487, 10 AddCircle 木卫2, 木星, 2, 0.3, 0, 6.3, , &H348888, 100 AddCircle 木卫3, 木星, 3, 0.35, 0, 5.4, , &HAA34CC, 190 AddCircle 木卫4, 木星, 4, 0.45, 0, 3.6, , &H888888, 280 AddCircle 土星, , 14, 5, 0.056, 0.36, 2.488
18、, &H2266CC AddCircle 土卫6, 土星, 4, 0.25, 0, 9.5, 30, &H99EEEE AddCircle 天王星, , 12, 6.5, 0.046, 0.27, 0.774, &HCC7777 AddCircle 天卫3, 天王星, 3, 0.2, 0, 9.6, , &H33FF88, 10 AddCircle 天卫4, 天王星, 3, 0.3, 0, 6.2, , &HFF3311, 200 AddCircle 海王星, , 12, 9.2, 0.009, 0.18, 1.774, &HFF7766 AddCircle 海卫1, 海王星, 3, 0.25
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 天体 运行 程序代码
限制150内