View Full Version : Drifting Colours


VilaRestal
06-25-2011, 07:04 AM
Not at all useful but quite a pleasant effect I think. Can be applied to any control that has either BackColor or ForeColor:


Private Sub Form_Timer()
DriftColors Label1
End Sub

Sub DriftColors(ByRef ctl As Control)
On Error Resume Next
Dim iR As Integer, iG As Integer, iB As Integer
RGBfromLongColor ctl.BackColor, iR, iG, iB
iR = DriftColor(iR)
iG = DriftColor(iG)
iB = DriftColor(iB)
ctl.BackColor = RGB(iR, iG, iB)
ctl.ForeColor = RGB(255 - iR, 255 - iG, 255 - iB)
End Sub

Function DriftColor(ByVal iCol As Integer)
If Rnd > 0.5 Then
iCol = iCol - 1
If iCol < 0 Then iCol = -iCol
Else
iCol = iCol + 1
If iCol > 255 Then iCol = 510 - iCol
End If
DriftColor = iCol
End Function

Sub RGBfromLongColor RGB(lColor As Long, iR As Integer, iG As Integer, iB As Integer)
iR = lColor Mod 256
iG = (lColor \ 256) Mod 256
iB = (lColor \ 256 \ 256) Mod 256
End Sub