Drifting Colours

VilaRestal

';drop database master;--
Local time
Today, 00:29
Joined
Jun 8, 2011
Messages
1,046
Not at all useful but quite a pleasant effect I think. Can be applied to any control that has either BackColor or ForeColor:

Code:
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
 

Users who are viewing this thread

Back
Top Bottom