0

i want to display all possible colors on a form (i am using timer with 500 interval).

what logic should be there to display all possible color (i want to display colors which are more closer to each other like red to pink not just red to black). color should be changed every half second with its closet matching color value.

and i don't know the how to implement logic.

how to use color value(0 to 255 ) for red , green , blue so that it looks that color change to its closest matching color value.

i hope that you underatnd what i want to do .

3
Contributors
6
Replies
23
Views
3 Years
Discussion Span
Last Post by Reverend Jim
0

i done with the code below and it shows color values but not all color values (i think that it can be more improved)...

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Static x, y, z As Integer
        If x < 255 Then
            BackColor = Color.FromArgb(x, y, z)
            x = x + 1
        ElseIf y < 255 Then
            BackColor = Color.FromArgb(x, y, z)
            y = y + 1
        ElseIf z < 255 Then
            BackColor = Color.FromArgb(x, y, z)
            z = z + 1
        Else
            Exit Sub
        End If
End Sub
0

Change your code to

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    Static x, y, z As Integer
    If x < 3 Then
        BackColor = Color.FromArgb(x, y, z)
        x = x + 1
    ElseIf y < 3 Then
        BackColor = Color.FromArgb(x, y, z)
        y = y + 1
    ElseIf z < 3 Then
        BackColor = Color.FromArgb(x, y, z)
        z = z + 1
    Else
        Timer1.Stop
    End If

    debug.writeline(x & " " & y & " " & z)

End Sub

And you will see your problem. When you fix the code for this case then you can change back to 255. What I think you want is

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

    Static x As Integer = -1
    Static y As Integer = 0
    Static z As Integer = 0
    Const maxval As Integer = 2

    If x < maxval Then
        x = x + 1
    ElseIf y < maxval Then
        x = 0
        y = y + 1
    ElseIf z < maxval Then
        x = 0
        y = 0
        z = z + 1
    Else
        Timer1.Stop()
    End If

    BackColor = Color.FromArgb(x, y, z)

End Sub

Edited by Reverend Jim

0

thanks for your reply but its not creating colors in a pattern what i think . it shows only black like color.

as a hint to understand the problem :
you can imagine that i want to show color changing every 10 ns . like we see while installing window 8 .(color changes to its nearest color )

Edited by Learner010

0

My bad. Change one line to

 Const maxval As Integer = 255

I had it set t0 2 when I was testing. However, you won't get smooth transitions when you reset from 255 to 0. To get a smoother transition you can try

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

    Static x As Integer = 1, dx = 1
    Static y As Integer = 1, dy = 1
    Static z As Integer = 1, dz = 1
    Const maxval As Integer = 255

    If x > 0 And x < maxval Then
        x += dx
    ElseIf y > 0 And y < maxval Then
        dx = -dx : x += dx
        y += dy
    ElseIf z < maxval Then
        dx = -dx : x += dx
        dy = -dy : y += dy
        z += dz
    Else
        Timer1.Stop()
    End If

    BackColor = Color.FromArgb(x, y, z)

End Sub

Edited by Reverend Jim

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.