Table of Contents

Struct GradientStop

Namespace
Egami.Drawing
Assembly
Egami.Drawing.dll

One color of a gradient at a position along it, from 0 (the start) to 1 (the end). Two stops at the same offset make a hard edge: the later one applies from that offset on. A gradient whose first stop is after 0 or whose last is before 1 repeats the nearest stop's color to the end, as CSS does.

public readonly record struct GradientStop : IEquatable<GradientStop>
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

GradientStop(float, InkColor)

Initializes a new instance of the GradientStop struct with a colour given as inks: an ink canvas blends the inks' tints; every other canvas uses Color, the appearance in sRGB.

public GradientStop(float offset, InkColor ink)

Parameters

offset float

The position along the gradient, from 0 to 1.

ink InkColor

The inks and their tints.

Exceptions

ArgumentOutOfRangeException

offset is outside 0 to 1.

ArgumentNullException

ink is null.

GradientStop(float, Rgba8)

Initializes a new instance of the GradientStop struct.

public GradientStop(float offset, Rgba8 color)

Parameters

offset float

The position along the gradient, from 0 to 1.

color Rgba8

The color.

Exceptions

ArgumentOutOfRangeException

offset is outside 0 to 1.

GradientStop(float, RgbaF32)

Initializes a new instance of the GradientStop struct.

public GradientStop(float offset, RgbaF32 color)

Parameters

offset float

The position along the gradient, from 0 to 1.

color RgbaF32

The color, with straight alpha.

Exceptions

ArgumentOutOfRangeException

offset is outside 0 to 1.

ArgumentException

A channel of color is not finite.

Properties

Color

Gets the color, with straight alpha: for an ink stop, its appearance in sRGB.

public RgbaF32 Color { get; }

Property Value

RgbaF32

Ink

Gets the colour as inks, or null for an RGB stop.

public InkColor? Ink { get; }

Property Value

InkColor

Offset

Gets the position along the gradient, from 0 to 1.

public float Offset { get; }

Property Value

float