五桂桥汽车站网上订票:编程:运动的一个圆

来源:百度文库 编辑:查人人中国名人网 时间:2024/05/03 02:14:06
问题:运动,在屏幕上显示一个在上下左右边界间运动的圆,该圆每碰撞一次边界就改变一次颜色并按照物理学规则反弹运动。
最好写出程序和提供相关保存文件,谢谢
^_^^_^^_^哈
最好是VB或者pascal(帕斯卡)编写

将以下代码保存为form1.frm再用VB打开运行就可以了。
我的QQ号是110807087,有事可以联系!

'————————form1.frm————————
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 4440
ClientLeft = 60
ClientTop = 450
ClientWidth = 7305
LinkTopic = "Form1"
ScaleHeight = 4440
ScaleWidth = 7305
StartUpPosition = 3 '窗口缺省
Begin VB.Timer Timer1
Interval = 40
Left = 4740
Top = 1515
End
Begin VB.Shape Shape2
Height = 4000
Left = 400
Top = 200
Width = 6400
End
Begin VB.Shape Shape1
BorderColor = &H00000000&
BorderStyle = 0 'Transparent
FillStyle = 0 'Solid
Height = 795
Left = 2820
Shape = 3 'Circle
Top = 870
Width = 795
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 intStep As Integer
Dim sinAngle As Single
Dim xAdd As Integer
Dim yAdd As Integer
Dim PI As Single
Dim i As Integer

Private Sub Form_Load()
intStep = 120 '步长,越长表示速度越快,但误差越大
Randomize
sinAngle = Rnd * 360
PI = 3.1415926
End Sub

Private Sub Timer1_Timer()
If Shape1.Top <= Shape2.Top Or Shape1.Top + Shape1.Height >= Shape2.Top + Shape2.Height Then '上下碰壁
sinAngle = 360 - sinAngle
i = i + 1: i = i Mod 16
Shape1.FillColor = QBColor(i)
End If
If Shape1.Left <= Shape2.Left Or Shape1.Left + Shape1.Width >= Shape2.Left + Shape2.Width Then '左右碰壁
sinAngle = 540 - sinAngle
i = i + 1: i = i Mod 16
Shape1.FillColor = QBColor(i)
End If
sinAngle = sinAngle Mod 360
xAdd = intStep * Sin(sinAngle / 180 * PI)
yAdd = intStep * Cos(sinAngle / 180 * PI)
Shape1.Left = Shape1.Left + yAdd
Shape1.Top = Shape1.Top - xAdd
End Sub

用VB的时间控件写 很简单的

下次给你

用c写最好了