Rotate Colours

This code smoothly rotates the colour of a picture box. Create a form and add a timer and a picture box name the picture box pic. Then add this code to the timer and watch the color rotate. Don’t forget to give an interval to the timer.

Static Red As Integer
Static Green As Integer
Static Blue As Integer
Static Color As Byte
Static Dir As Boolean
   Randomize
   If Rnd < 0.05 Then
       Color = Int(3 * Rnd)
   End If
   Select Case Color
   Case 0
       If Red > 240 Then
           Dir = False
       ElseIf Red < 15 Then
           Dir = True
       End If
       If Dir = True Then
           Red = Red + 10
       Else
           Red = Red - 10
       End If
   Case 1
       If Green > 240 Then
           Dir = False
       ElseIf Green < 15 Then
           Dir = True
       End If
       If Dir = True Then
           Green = Green + 10
       Else
           Green = Green - 10
       End If
   Case 2
       If Blue > 240 Then
           Dir = False
       ElseIf Blue < 15 Then
           Dir = True
       End If
       If Dir = True Then
           Blue = Blue + 10
       Else
           Blue = Blue - 10
       End If
   End Select
   Pic.BackColor = RGB(Red, Green, Blue)

You might also like...

Comments

Nick Avery I am as a web developer for a small company, working for a small company. I work on banking websites and verious related projects.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Brevity is the soul of wit” - Shakespeare