tags:

views:

403

answers:

3
+1  Q: 

Arc based gradient

I am trying to create an arc (variable width, variable number of degrees - potentially an entire circle) that gradually goes from, say, red on one end to green on the other. I haven't figured out how to specify a gradient on an arc to accomplish this.

For example, if you could imagine creating a round temperature gauge where the guage marker points at the varying degrees on the circle from 0 to 500. As an added visual, I would like the gauge circumference to have a gradient color signifying the gauge temperature - going from cool (green) to very hot (red).

I have tried both PathGradientBrush and LinerarGradientBrush (but maybe I missed something). Radial gradients don't seem to give me what I need either.

Any ideas would help.

Thanks.

+1  A: 
Paul Dixon
I am using C#.The problem is that I don't know how to fill a circular path with a gradient that follows the circle. I need the gradient direction to follow the circle, not a rectangle. What I am seeing when I gradient fill (or draw with a LinearGradient Pen) is that the gradient is applied (by default) from left to right. If I draw in a circle, then then entire left of the circle is one color, blending into the end color to the right of the circle. I want to start with one color at a given point on the circle, and end with another at another point.
You could draw the arc iteratively - e.g. calc points on arc for degree 0 and degree 1, calculuate hue for that point in arc, draw line in that hue. Then do degree 1 to 2, and so on.
Paul Dixon
+1  A: 

This code will create an arc that goes from red to green (left to right). It just draws on the form.

private void button1_Click(object sender, EventArgs e)
{
    using (Graphics g = this.CreateGraphics())
    {
        LinearGradientBrush lgb = new LinearGradientBrush(new Point(0, 0), new Point(210, 0), Color.Red, Color.Green);
        Pen p = new Pen(lgb, 10);
        g.DrawArc(p, 10, 10, 200, 200, -22.5f, -135f);

    }
}

This will work for arcs up to 180 degrees. I'd have to think about doing it for a full circle.

Jim Mischel
Yep, going over the 180 degree mark is the issue I was wondering if there was a clean solution for. At this point I will probably break the circle up into 4 quadrants to draw the gradient arc so that it looks as best as possible.Thanks for the input. :-)
A: 

I am developing a component and for backcolor, how can i diaplay radial gradient in rectangle withoout using WPF framework. i the rectangle below i want to display col1, color2, and col3 in gradient pattern.i dont how to give gradient effect of col3.please help me

---------------------| | color1 | | ---------------------| . . color2 | . . | . color3 . | ---------------------|