0

im trying rotate the colors for a draw feature, any one done someting similar and can help make it look good.

    byte r = 200;
    byte g = 100;
    byte b = 050;

    private int x = 1;

    private void timer_elapsed(object sender, EventArgs e)
    {
        x++;

        if(x % 3 == 0)
         r++;

        if(x % 5 == 0)
        g++;

        if(x % 2 == 0)
        b++;

        if (x > 100)
            x = 1;

        if (r >= 254)
            r = 0;
        if (g >= 254)
            g = 0;
        if (b >= 254)
            b = 0;

        inkCanvas1.DefaultDrawingAttributes.Color = Color.FromArgb(255, r, g, b);
    }

edit

buy rotate colors i mean i want my brush to fade from red to blue and from blue to green then yellow and back to red, iv done som more looking in to this and this is what i want

254,0,0     = red
254,0,254   = pink
0,0,254     = blue
0,254,254   = cyan
0,254,0 = green
254,254,0   = yellow
254,0,0 = red

so am I looking at doing simple if statement here or can i do this in a smarter way?


edit

my current logic is this

    byte r = 255;
    byte g = 0;
    byte b = 0;


    private void timer_elapsed(object sender, EventArgs e)
    {
        //going from red to pink
        if (r == 255 && g == 0  && b <= 254)
            b++;
        //going from pink to blue
        if (r >= 1 && g == 0 && b == 255 )
            r--;
        //going from blue to cyan
        if (r == 0 && g <= 254 && b == 255 )
            g++;
        //going from cyan to green
        if (r == 0 && g == 255 && b >= 1)
            b--;
        //going from green to yellow
        if (r <= 254 && g == 255 && b == 0)
            r++;
        //going from yellow back to red
        if (r == 255 && g >= 1 && b == 0)
            g--;

        inkCanvas1.DefaultDrawingAttributes.Color = Color.FromArgb(255, r, g, b);
    }
Darkmage
  • 1,583
  • 9
  • 24
  • 42

1 Answers1

2

If you want to achieve that your color changes in a smooth way, you should consider using the HSV color space. Actually, the hue value (H) is measured in degrees which results in a rotating color when you increase this value and leave the others.

Here's a way to convert HSV space to a default color. I think, you should be able to convert the VB code to C#.

Nico Schertler
  • 32,049
  • 4
  • 39
  • 70