|
-
Jan 22nd, 2019, 11:10 AM
#8
Re: How can I make a label fade through colors with a timer?
I've done this a few times. Rather than adding 1, I add a small prime number, as I felt that there are too many colors for people to really see the difference if all you are adding is 1. I'm also adding to R, G, and B, though different amounts to each one, which means that they are going in different directions at all time. The result can be a bit hypnotic. Eventually, every color should be reached, but there is no consistent pattern to it.
The code looks like this:
Code:
Private curB As Integer
Private curR As Integer
Private curG As Integer
Private dirB As Integer = 1
Private dirR As Integer = 1
Private dirG As Integer = -1
Private rd As New Random
Private Sub UpdateBackground()
curB += 13 * dirB
curR += 7 * dirR
curG += 11 * dirG
If curB > 255 Then
curB = 255 - (curB - 255)
dirB = -1
ElseIf curB < 0 Then
curB = -curB
dirB = 1
End If
If curR > 255 Then
curR = 255 - (curR - 255)
dirR = -1
ElseIf curR < 0 Then
curR = -curR
dirR = 1
End If
If curG > 255 Then
curG = 255 - (curG - 255)
dirG = -1
ElseIf curG < 0 Then
curG = -curG
dirG = 1
End If
SomeLabel.BackColor = System.Drawing.Color.FromArgb(curR, curG, curB)
SomeLabel.Refresh()
End Sub
My usual boring signature: Nothing
 
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|