Arc based gradient

I am trying to create an arc (variable width, variable number of degrees - potentially a whole circle), which gradually switches, say, from one end to green to the other. I did not understand how to specify the gradient on the arc in order to accomplish this.

For example, if you could create a circular temperature gauge, where the marker marker points to varying degrees on a circle from 0 to 500. As an additional visualization, I would like the caliber circle to have a gradient color, indicating (from green) to very hot ( red).

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

Any ideas will help.

Thanks.

+3
source share
2 answers

This code will create an arc that goes from red to green (from left to right). It simply relies on 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 need to think about doing it for the full circle.

+3
source

You did not specify the language that you are using, but in general terms you can use a color model, for example, Hue hue value (HSV) , and hue cycle from 0 degrees (red) to 120 degrees (green), which regardless of saturation and value suits you .

Here is an illustration - the upper gradient goes only from green to red in the RGB model, but the lower one uses HSV, which leads to a more pleasant effect.

alt text http://i38.tinypic.com/29o0q4k.jpg

+2
source

Source: https://habr.com/ru/post/1713457/


All Articles