7,763
社区成员
发帖
与我相关
我的任务
分享
'集合方式
Option Explicit
Private Declare Function GetTickCount Lib "kernel32.dll" () As Long
Dim oFlashs As Collection '使用集合来存储每个对象
Private Sub Form_Load()
Dim I As Long, J As cCir, K As cPane
Set oFlashs = New Collection
For I = 0 To 499 '圆与方框各500个
Set J = New cCir
With J
.Color1 = vbRed
.Color2 = vbBlue
.Time1 = Int(Rnd * 1000 + 1000) '随机时间
.Time2 = Int(Rnd * 1000 + 2000)
.X = Int(Rnd * Picture1.Width) '随机位置
.Y = Int(Rnd * Picture1.Height)
Set .PicObject = Picture1 '传入绘图对象
End With
oFlashs.Add J '添加到集合
Next
For I = 500 To 999
Set K = New cPane
With K
.Color1 = vbBlack
.Color2 = vbWhite
.Time1 = Int(Rnd * 300 + 200)
.Time2 = Int(Rnd * 400 + 300)
.X = Int(Rnd * Picture1.Width)
.Y = Int(Rnd * Picture1.Height)
Set .PicObject = Picture1
End With
oFlashs.Add K
Next
End Sub
Private Sub Command1_Click()
Timer1.Enabled = Not Timer1.Enabled
End Sub
Private Sub Timer1_Timer()
Static FPS As Long, K As Long, L As Long
Dim I As Long, J As Long
J = GetTickCount
Picture1.Cls
For I = 1 To oFlashs.Count
Call oFlashs.Item(I).DrawObject(J) '绘图时,传入当前时间,对象自己决定当前绘制状态.由于后期绑定,性能有影响.
Next
If GetTickCount - K > 1000 Then
K = GetTickCount
L = FPS
FPS = 0
End If
Picture1.CurrentX = 0
Picture1.CurrentY = 0
Picture1.Print "FPS = " & L & ",总对象数量=" & I - 1
FPS = FPS + 1
End Sub
'继承方式
Option Explicit
Private Declare Function GetTickCount Lib "kernel32.dll" () As Long
Dim oFlashs() As cInterFace '声明为接口类,则此处已是前期绑定.
Private Sub Form_Load()
Dim I As Long
ReDim oFlashs(999) '一共1000个对象
For I = 0 To 499
Set oFlashs(I) = New cCir '将接口实例化为一个已继承此接口的对象
With oFlashs(I)
.Color1 = vbRed
.Color2 = vbBlue
.Time1 = Int(Rnd * 1000 + 1000) '随机时间
.Time2 = Int(Rnd * 1000 + 2000)
.X = Int(Rnd * Picture1.Width) '随机位置
.Y = Int(Rnd * Picture1.Height)
Set .PicObject = Picture1 '绘图对象
End With
Next
For I = 500 To 999
Set oFlashs(I) = New cPane
With oFlashs(I)
.Color1 = vbBlack
.Color2 = vbWhite
.Time1 = Int(Rnd * 300 + 200)
.Time2 = Int(Rnd * 400 + 300)
.X = Int(Rnd * Picture1.Width)
.Y = Int(Rnd * Picture1.Height)
Set .PicObject = Picture1
End With
Next
End Sub
Private Sub Command1_Click()
Timer1.Enabled = Not Timer1.Enabled
End Sub
Private Sub Timer1_Timer()
Static FPS As Long, K As Long, L As Long
Dim I As Long, J As Long
J = GetTickCount
Picture1.Cls
For I = 0 To UBound(oFlashs)
Call oFlashs(I).DrawObject(J) '此处的调用,已是对已知接口的调用,性能比集合更高
Next
If GetTickCount - K > 1000 Then
K = GetTickCount
L = FPS
FPS = 0
End If
Picture1.CurrentX = 0
Picture1.CurrentY = 0
Picture1.Print "FPS = " & L & ",总对象数量=" & I
FPS = FPS + 1
End Sub
Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type LEDProperty
MaxCount As Long
NowCount As Long
State As Long
End Type
Dim LEDCount As Long
Dim LEDPA() As LEDProperty
Private Sub Form_Load()
Dim i As Long
Dim x As Long
Dim y As Long
Dim wCount As Long
Dim hCount As Long
Dim dwWidth As Long
Dim wRect As RECT
'========================================
' 注意 LED.Index 不能为空,将其设置为 0
'========================================
dwWidth = (15 * 12)
GetClientRect Me.hwnd, wRect
wCount = (wRect.Right * 15) / dwWidth
hCount = (wRect.Bottom * 15) / dwWidth
LEDCount = wCount * hCount - 1
ReDim LEDPA(LEDCount)
Randomize
LEDPA(0).MaxCount = Int((60 * Rnd) + 0)
LEDPA(0).NowCount = LEDPA(0).MaxCount
If Int((2 * Rnd) + 0) Then
LEDPA(0).State = 0
Else
LEDPA(0).State = 1
End If
LED(0).Move 0, 0, dwWidth, dwWidth
LED(0).Enabled = False
' 动态加载99个名为LED的 PictureBox 控件
For i = 1 To LEDCount
x = x + 1
If x >= wCount Then
x = 0
y = y + 1
End If
' 加载新的控件数组元素
Load LED(i)
' 像控件数组元素的 Tag 属性随机分配一个 0-60 之间的整数
LEDPA(i).MaxCount = Int((60 * Rnd) + 0)
LEDPA(i).NowCount = LEDPA(i).MaxCount
' 随机设置控件的背景色为红色或绿色
If Int((2 * Rnd) + 0) Then
LED(i).BackColor = &HFF&
LEDPA(i).State = 0
Else
LED(i).BackColor = &HFF00&
LEDPA(i).State = 1
End If
LED(i).Move x * dwWidth, y * dwWidth, dwWidth, dwWidth
LED(i).Visible = True
LED(i).Enabled = False
Next i
Timer1.Interval = 1
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Dim i As Long
Dim lngColor1 As Long
Dim lngColor2 As Long
Dim by1Red As Long
Dim by1Green As Long
Dim by1Blue As Long
Dim by2Red As Long
Dim by2Green As Long
Dim by2Blue As Long
Dim cRed As Long
Dim cGreen As Long
Dim cBlue As Long
Dim AP As Double
Dim 比例
Randomize
For i = 0 To LEDCount
' 判断每个控件当前色存活的时间是否已要完结
If LEDPA(i).NowCount <= 1 Then
' 判断原来如果是红色就变绿色,是绿色就变红色
If LEDPA(i).State = 0 Then
LED(i).BackColor = &HFF&
LEDPA(i).State = 1
Else
LED(i).BackColor = &HFF00&
LEDPA(i).State = 0
End If
' 重新随机给颜色设置一个存活时间
LEDPA(i).MaxCount = Int((100 * Rnd) + 0)
LEDPA(i).NowCount = LEDPA(i).MaxCount
Else
If LEDPA(i).State = 0 Then
lngColor1 = &HFF&
lngColor2 = &HFF00&
Else
lngColor1 = &HFF00&
lngColor2 = &HFF&
End If
by1Red = lngColor1 And &HFF: lngColor1 = Int(lngColor1 / (2 ^ 8))
by1Green = lngColor1 And &HFF: lngColor1 = Int(lngColor1 / (2 ^ 8))
by1Blue = lngColor1 And &HFF
by2Red = lngColor2 And &HFF: lngColor2 = Int(lngColor2 / (2 ^ 8))
by2Green = lngColor2 And &HFF: lngColor2 = Int(lngColor2 / (2 ^ 8))
by2Blue = lngColor2 And &HFF
AP = 255 / LEDPA(i).MaxCount
cRed = by1Red + Round(((by2Red - by1Red) / 255) * (AP * LEDPA(i).NowCount))
cGreen = by1Green + Round(((by2Green - by1Green) / 255) * (AP * LEDPA(i).NowCount))
cBlue = by1Blue + Round(((by2Blue - by1Blue) / 255) * (AP * LEDPA(i).NowCount))
cRed = IIf(cRed > 255, 255, IIf(cRed < 0, 0, cRed))
cGreen = IIf(cGreen > 255, 255, IIf(cGreen < 0, 0, cGreen))
cBlue = IIf(cBlue > 255, 255, IIf(cBlue < 0, 0, cBlue))
LED(i).BackColor = RGB(cRed, cGreen, cBlue)
LEDPA(i).NowCount = LEDPA(i).NowCount - 1
End If
Next i
End Sub
Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Dim LEDCount As Long
Private Sub Form_Load()
Dim i As Long
Dim x As Long
Dim y As Long
Dim wCount As Long
Dim hCount As Long
Dim dwWidth As Long
Dim wRect As RECT
'========================================
' 注意 LED.Index 不能为空,将其设置为 0
'========================================
dwWidth = (15 * 12)
GetClientRect Me.hwnd, wRect
wCount = (wRect.Right * 15) / dwWidth
hCount = (wRect.Bottom * 15) / dwWidth
LEDCount = wCount * hCount - 1
Randomize
LED(0).Tag = Int((60 * Rnd) + 0)
If Int((2 * Rnd) + 0) Then
LED(0).BackColor = &HFF&
Else
LED(0).BackColor = &HFF00&
End If
LED(0).Move 0, 0, dwWidth, dwWidth
' 动态加载99个名为LED的 PictureBox 控件
For i = 1 To LEDCount
x = x + 1
If x >= wCount Then
x = 0
y = y + 1
End If
' 加载新的控件数组元素
Load LED(i)
' 像控件数组元素的 Tag 属性随机分配一个 0-60 之间的整数
LED(i).Tag = Int((60 * Rnd) + 0)
' 随机设置控件的背景色为红色或绿色
If Int((2 * Rnd) + 0) Then
LED(i).BackColor = &HFF&
Else
LED(i).BackColor = &HFF00&
End If
LED(i).Move x * dwWidth, y * dwWidth, dwWidth, dwWidth
LED(i).Visible = True
Next i
Timer1.Interval = 1
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Dim i As Long
Randomize
For i = 0 To LEDCount
' 判断每个控件当前色存活的时间是否已要完结
If Int(LED(i).Tag) <= 1 Then
' 判断原来如果是红色就变绿色,是绿色就变红色
If LED(i).BackColor = &HFF& Then
LED(i).BackColor = &HFF00&
Else
LED(i).BackColor = &HFF&
End If
' 重新随机给颜色设置一个存活时间
LED(i).Tag = Int((60 * Rnd) + 0)
Else
LED(i).Tag = Int(LED(i).Tag) - 1
End If
Next i
End Sub
Private Sub Form_Load()
Dim i As Long
Dim x As Long
Dim y As Long
Dim wCount As Long
Dim dwWidth As Long
'========================================
' 注意 LED.Index 不能为空,将其设置为 0
'========================================
dwWidth = (15 * 12)
wCount = (Me.Width - 15 * 6) / dwWidth
Randomize
LED(0).Tag = Int((60 * Rnd) + 0)
If Int((2 * Rnd) + 0) Then
LED(0).BackColor = &HFF&
Else
LED(0).BackColor = &HFF00&
End If
LED(0).Move 0, 0, dwWidth, dwWidth
' 动态加载99个名为LED的 PictureBox 控件
For i = 1 To 99
x = x + 1
If x >= wCount Then
x = 0
y = y + 1
End If
' 加载新的控件数组元素
Load LED(i)
' 像控件数组元素的 Tag 属性随机分配一个 0-60 之间的整数
LED(i).Tag = Int((60 * Rnd) + 0)
' 随机设置控件的背景色为红色或绿色
If Int((2 * Rnd) + 0) Then
LED(i).BackColor = &HFF&
Else
LED(i).BackColor = &HFF00&
End If
LED(i).Move x * dwWidth, y * dwWidth, dwWidth, dwWidth
LED(i).Visible = True
Next i
Timer1.Interval = 100
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Dim i As Long
Randomize
For i = 0 To 99
' 判断每个控件当前色存活的时间是否已要完结
If Int(LED(i).Tag) <= 1 Then
' 判断原来如果是红色就变绿色,是绿色就变红色
If LED(i).BackColor = &HFF& Then
LED(i).BackColor = &HFF00&
Else
LED(i).BackColor = &HFF&
End If
' 重新随机给颜色设置一个存活时间
LED(i).Tag = Int((60 * Rnd) + 0)
Else
LED(i).Tag = Int(LED(i).Tag) - 1
End If
Next i
End Sub