Class ConicalGradient
A gradient between two circles, as the HTML canvas's createRadialGradient, Skia's two-point conical gradient and a PDF type 3 shading define it: for each t, the circle whose center and radius are t of the way from the start circle to the end one; a pixel takes the largest t whose circle passes through it with a radius of at least 0. It covers a focal point inside a circle (a start radius of 0), one circle inside the other, and cones drawn on one side only.
public sealed record ConicalGradient : Gradient, ITextPaint, IEquatable<Paint>, IEquatable<Gradient>, IEquatable<ConicalGradient>
- Inheritance
-
ConicalGradient
- Implements
- Inherited Members
Examples
using (RasterCanvas<Rgba8> canvas = raster.CreateCanvas())
{
// Two colors along a line; past the ends the end colors repeat (TileMode.Clamp).
canvas.FillRect(new RectF(0, 0, 200, 100), new LinearGradient(new Vector2(0, 0), new Vector2(200, 0), new RgbaF32(0.1f, 0.3f, 0.9f, 1), new RgbaF32(1, 0.8f, 0.2f, 1)));
// Several stops, mixed in Oklab for even midpoints, repeating every 40 pixels.
canvas.FillRect(new RectF(200, 0, 200, 100), new LinearGradient(
new Vector2(200, 0),
new Vector2(240, 0),
new GradientStop(0, new Rgba8(230, 40, 60, 255)),
new GradientStop(0.5f, new Rgba8(250, 210, 60, 255)),
new GradientStop(1, new Rgba8(230, 40, 60, 255)))
{
Tile = TileMode.Repeat,
Interpolation = GradientInterpolation.Oklab,
});
// A radial gradient stretched into an ellipse by its local matrix, and a sweep around a center.
canvas.FillOval(new RectF(10, 110, 180, 80), new RadialGradient(Vector2.Zero, 1, new RgbaF32(1, 1, 1, 1), new RgbaF32(0, 0.4f, 0.2f, 1))
{
LocalMatrix = Matrix3x2.CreateScale(90, 40) * Matrix3x2.CreateTranslation(100, 150),
});
canvas.FillCircle(new Vector2(300, 150), 45, new SweepGradient(
new Vector2(300, 150),
new GradientStop(0, new Rgba8(255, 0, 0, 255)),
new GradientStop(0.5f, new Rgba8(0, 0, 255, 255)),
new GradientStop(1, new Rgba8(255, 0, 0, 255))));
}
Constructors
ConicalGradient(Vector2, float, Vector2, float, params ReadOnlySpan<GradientStop>)
Initializes a new instance of the ConicalGradient class.
public ConicalGradient(Vector2 start, float startRadius, Vector2 end, float endRadius, params ReadOnlySpan<GradientStop> stops)
Parameters
startVector2The start circle's center, in paint coordinates.
startRadiusfloatThe start circle's radius, where t is 0.
endVector2The end circle's center.
endRadiusfloatThe end circle's radius, where t is 1.
stopsReadOnlySpan<GradientStop>The stops; at least one.
Exceptions
- ArgumentException
A center is not finite, or there are no stops.
- ArgumentOutOfRangeException
A radius is negative or not finite.
Properties
End
Gets the end circle's center.
public Vector2 End { get; init; }
Property Value
Exceptions
- ArgumentException
The point is not finite.
EndRadius
Gets the end circle's radius.
public float EndRadius { get; init; }
Property Value
Exceptions
- ArgumentOutOfRangeException
The value is negative or not finite.
Start
Gets the start circle's center.
public Vector2 Start { get; init; }
Property Value
Exceptions
- ArgumentException
The point is not finite.
StartRadius
Gets the start circle's radius.
public float StartRadius { get; init; }
Property Value
Exceptions
- ArgumentOutOfRangeException
The value is negative or not finite.