RadialGradientBrush Class

A gradient around a point: the color is constant on circles around that point.

public sealed class RadialGradientBrush : GradientBrush

Remarks

The parameter of a position is its distance to RadialGradientBrush.Center divided by RadialGradientBrush.Radius. When the radius is zero, the whole canvas has the color of the last stop.

With a RadialGradientBrush.FocalPoint that is not the center, the gradient spreads from the focal point to the circle of RadialGradientBrush.Center and RadialGradientBrush.Radius: the parameter of a position is how far it is from the focal point, as a fraction of the distance from the focal point to that circle in the same direction. The circle of a parameter t is centered t of the way from the focal point to the center, with a radius of t times RadialGradientBrush.Radius.

With a RadialGradientBrush.FocalRadius, the gradient starts on a circle around the focal point instead of at that point: the gradient between two circles of SVG 2 (fr) and of the HTML canvas. The circle of a parameter t is still centered t of the way from the focal point to the center, and its radius goes from RadialGradientBrush.FocalRadius to RadialGradientBrush.Radius. Inside the circle of the focal point, the parameter is negative: the color is the one of the first stop with GradientSpreadMode.Pad, and the gradient goes on toward the point where its circles shrink to nothing with the other spread modes.

The two circles can be anywhere, as for createRadialGradient of the HTML canvas: the circles of the parameters t (all of them, not only those from 0 to 1) whose radius r(t) is not negative form a cone, and a position has the largest t whose circle goes through it. A position that no such circle goes through (outside the cone) has no color: nothing is painted there, whatever the spread mode. When the first circle is inside the second one, every position has a parameter, and this is the gradient described above. Two circles of the same center and the same radius make no cone: with GradientSpreadMode.Pad, the inside of the circle has the color of the first stop and the rest of the canvas the color of the last one; with the other spread modes, nothing is painted.

With a RadialGradientBrush.RadiusY that is not RadialGradientBrush.Radius, the color is constant on ellipses instead: the circles above are stretched along y around RadialGradientBrush.Center by RadiusY / Radius, before GradientBrush.Transform, which can still turn them. This is the radial gradient with a GradientBrush.Transform that scales y around the center, written with the half-axes of the ellipse.

Inheritance
GradientBrush RadialGradientBrush

Constructors

NameDescription
RadialGradientBrush(PointD, double, double, ReadOnlySpan<GradientStop>)Initializes a new instance of the RadialGradientBrush class whose color is constant on ellipses around a point.
RadialGradientBrush(PointD, double, ReadOnlySpan<GradientStop>)Initializes a new instance of the RadialGradientBrush class.

RadialGradientBrush overloads

RadialGradientBrush(PointD, double, double, ReadOnlySpan<GradientStop>)

RadialGradientBrush.cs

Initializes a new instance of the RadialGradientBrush class whose color is constant on ellipses around a point.

public RadialGradientBrush(PointD center, double radiusX, double radiusY, ReadOnlySpan<GradientStop> stops)
Parameters
center PointD
The position of offset 0, in canvas coordinates.
radiusX double
The half-axis along x of the ellipse of offset 1. Must be zero or positive.
radiusY double
The half-axis along y of the ellipse of offset 1. Must be zero or positive.
stops ReadOnlySpan<GradientStop>
The stops, in increasing order of offset. They are copied.
Exceptions
ArgumentException
There is no stop, the offsets decrease, or a coordinate or a half-axis is not a finite number.
ArgumentOutOfRangeException
The magnitude of a coordinate exceeds 16777216, or a half-axis is negative or exceeds 16777216.
Remarks

The gradient is the circular gradient of radius radiusX, stretched along y around center by radiusY / radiusX, before GradientBrush.Transform: the parameter of a position p is sqrt(dx^2 + (dy radiusX / radiusY)^2) / radiusX, with (dx, dy) = p - center. When one of the half-axes is zero and the other is not, the whole canvas has the color of the last stop.

RadialGradientBrush(PointD, double, ReadOnlySpan<GradientStop>)

RadialGradientBrush.cs

Initializes a new instance of the RadialGradientBrush class.

public RadialGradientBrush(PointD center, double radius, ReadOnlySpan<GradientStop> stops)
Parameters
center PointD
The position of offset 0, in canvas coordinates.
radius double
The distance from the center at which the offset is 1. Must be zero or positive.
stops ReadOnlySpan<GradientStop>
The stops, in increasing order of offset. They are copied.
Exceptions
ArgumentException
There is no stop, the offsets decrease, or a coordinate or the radius is not a finite number.
ArgumentOutOfRangeException
The magnitude of a coordinate exceeds 16777216, or the radius is negative or exceeds 16777216.

Properties

NameDescription
CenterGets the center of the circle of offset 1; the position of offset 0 unless there is a RadialGradientBrush.FocalPoint.
FocalPointGets the position of offset 0: the point the gradient spreads from, or the center of the circle it starts on. Defaults to RadialGradientBrush.Center.
FocalRadiusGets the radius of the circle of offset 0, around RadialGradientBrush.FocalPoint: the gradient starts on that circle. Defaults to 0: the gradient starts at the focal point.
RadiusGets the distance from the center at which the offset is 1: the radius of the circle of offset 1, or the half-axis along x of its ellipse.
RadiusYGets the half-axis along y of the ellipse of offset 1: RadialGradientBrush.Radius for a circular gradient.

Gets the center of the circle of offset 1; the position of offset 0 unless there is a RadialGradientBrush.FocalPoint.

public PointD Center { get; }

Property value

PointD

Gets the position of offset 0: the point the gradient spreads from, or the center of the circle it starts on. Defaults to RadialGradientBrush.Center.

public PointD FocalPoint { get; init; }

Property value

PointD

Exceptions

ArgumentException
A coordinate is not a finite number.
ArgumentOutOfRangeException
The magnitude of a coordinate exceeds 16777216.

Gets the radius of the circle of offset 0, around RadialGradientBrush.FocalPoint: the gradient starts on that circle. Defaults to 0: the gradient starts at the focal point.

public double FocalRadius { get; init; }

Property value

double

Exceptions

ArgumentException
The value is not a finite number.
ArgumentOutOfRangeException
The value is negative or exceeds 16777216.

Gets the distance from the center at which the offset is 1: the radius of the circle of offset 1, or the half-axis along x of its ellipse.

public double Radius { get; }

Property value

double

Gets the half-axis along y of the ellipse of offset 1: RadialGradientBrush.Radius for a circular gradient.

public double RadiusY { get; }

Property value

double

Remarks

When it differs from RadialGradientBrush.Radius, every circle of the gradient is stretched along y around RadialGradientBrush.Center by RadiusY / Radius: RadialGradientBrush.FocalPoint is the position of offset 0 after that stretch, and RadialGradientBrush.FocalRadius the half-axis along x of the ellipse of offset 0.