Table of Contents

Class SweepGradient

Namespace
Egami.Drawing
Assembly
Egami.Drawing.dll

A gradient around a center, as Skia's sweep gradient and CSS's conic-gradient: t goes from 0 at StartAngle to 1 at EndAngle, in degrees clockwise (on a y-down screen) from the positive x axis.

public sealed record SweepGradient : Gradient, ITextPaint, IEquatable<Paint>, IEquatable<Gradient>, IEquatable<SweepGradient>
Inheritance
SweepGradient
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

SweepGradient(Vector2, params ReadOnlySpan<GradientStop>)

Initializes a new instance of the SweepGradient class going once around.

public SweepGradient(Vector2 center, params ReadOnlySpan<GradientStop> stops)

Parameters

center Vector2

The center, in paint coordinates.

stops ReadOnlySpan<GradientStop>

The stops; at least one.

Exceptions

ArgumentException

The center is not finite, or there are no stops.

SweepGradient(Vector2, float, float, params ReadOnlySpan<GradientStop>)

Initializes a new instance of the SweepGradient class between two angles.

public SweepGradient(Vector2 center, float startAngle, float endAngle, params ReadOnlySpan<GradientStop> stops)

Parameters

center Vector2

The center, in paint coordinates.

startAngle float

Where t is 0, in degrees.

endAngle float

Where t is 1, in degrees, after startAngle.

stops ReadOnlySpan<GradientStop>

The stops; at least one.

Exceptions

ArgumentException

The center is not finite, or there are no stops.

ArgumentOutOfRangeException

An angle is not finite, or endAngle is not after startAngle.

Properties

Center

Gets the center, in paint coordinates.

public Vector2 Center { get; init; }

Property Value

Vector2

Exceptions

ArgumentException

The point is not finite.

EndAngle

Gets the angle where t is 1, in degrees. Defaults to 360.

public float EndAngle { get; }

Property Value

float

StartAngle

Gets the angle where t is 0, in degrees. Defaults to 0.

public float StartAngle { get; }

Property Value

float