Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Radial Sweeping of a Brush

Tags:

c#

wpf

I'm looking for a way to fill something using a radial sweep of a defined brush in WPF. I'm going to break down what I want in a series of images in an attempt to make it clear.

Let's say I define a brush in WPF that looks like so:

Brush

I then want to use a slice of that brush like so:

Brush with Slice

And tile it across the radius of a circle as shown:

Tiling the Radius

Finally, in order to fill the shape, I would like to sweep the brush across all angles of the circle, providing me with a result similar to this:

Sweeping the Circle

In this particular case I'm attempting to make concentric circles. I know I could achieve this using RadialGradientBrush but this is an obnoxious solution as in order to precisely control the width of my concentric circles I would need change the number of radial stops based on the size of the circle. To make it worse, if the circle size changes, the radial stops will not change unless I use some kind of converter based on the circle width/height.

I was hoping for a clean solution to do this maybe with paths or something but any other suggestions for making circle slices of controlled size is welcome.

like image 523
Jas Laferriere Avatar asked Nov 19 '25 21:11

Jas Laferriere


1 Answers

How about this to draw a few concentric circles by use of a Brush?

<Rectangle>
    <Rectangle.Fill>
        <DrawingBrush Stretch="Uniform">
            <DrawingBrush.Drawing>
                <GeometryDrawing>
                    <GeometryDrawing.Pen>
                        <Pen Brush="Black" Thickness="1"/>
                    </GeometryDrawing.Pen>
                    <GeometryDrawing.Geometry>
                        <GeometryGroup>
                            <EllipseGeometry RadiusX="1" RadiusY="1"/>
                            <EllipseGeometry RadiusX="3" RadiusY="3"/>
                            <EllipseGeometry RadiusX="5" RadiusY="5"/>
                            <EllipseGeometry RadiusX="7" RadiusY="7"/>
                            <EllipseGeometry RadiusX="9" RadiusY="9"/>
                            <EllipseGeometry RadiusX="11" RadiusY="11"/>
                        </GeometryGroup>
                    </GeometryDrawing.Geometry>
                </GeometryDrawing>
            </DrawingBrush.Drawing>
        </DrawingBrush>
    </Rectangle.Fill>
</Rectangle>
like image 80
Clemens Avatar answered Nov 21 '25 12:11

Clemens