求大神帮忙解决一下“跳动的小球” 4月18日之前需要参考一下 谢谢
有没有大神帮忙做一个跳动的小球 球会自己变色 背景也会自己变色 最好就是那个圆还会变形状 现在急需参考 谢谢
程序代码:
Option Explicit '在窗体上放一个Picture1,在Picture1里放一个Shape1 'DEBUG是放一个 Label1 ,拉高一点,需要显示5行数据,同时下面 语句注释去掉 Dim qx As Long, qy As Long '球坐标 Dim qxb As Long, qyb As Long '变化量 Dim r1 As Long, g1 As Long, b1 As Long '颜色 Dim rb As Long, gb As Long, bb As Long '颜色变化 Private Sub Form_Load() Timer1.Interval = 50 '定时器 Shape1.Shape = 3 '圆形 Shape1.FillStyle = 0 '填充模式 qx = Shape1.Left qy = Shape1.Top qxb = 120 qyb = 120 rb = 16 gb = 16 bb = 16 End Sub Private Sub Timer1_Timer() If cb(b1, bb, 0, 255) Then If cb(g1, gb, 0, 255) Then Call cb(r1, rb, 0, 255) End If End If Picture1.BackColor = RGB(r1, g1, b1) Shape1.FillColor = RGB(255 - r1, 255 - g1, 255 - b1) '小球我这里使用补色 Call cb(qx, qxb, 0, Picture1.ScaleWidth - Shape1.Width) Call cb(qy, qyb, 0, Picture1.ScaleHeight - Shape1.Height) Shape1.Move qx, qy 'DEBUG Label1.Caption = "X:" & qx & vbCrLf & "Y:" & qy & vbCrLf & "R:" & r1 & vbCrLf & "G:" & g1 & vbCrLf & "B:" & b1 End Sub Public Function cb(C As Long, b As Long, CS As Long, CE As Long) As Boolean '计算过程,超限会设置标志位 'c 计算变量 ,b 变化量,CS 最小值,CE 最大值 '变化量是在正负之间跳动 cb = False C = C + b If C > CE Then C = CE b = -b cb = True ElseIf C < CS Then C = CS b = -b cb = True End If End Function