Show / Hide Table of Contents

    Struct Color

    A color with red, green, blue, and alpha components.

    Implements
    System.IEquatable<Color>
    Inherited Members
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetType()
    System.Object.ReferenceEquals(System.Object, System.Object)
    Namespace: Elements.Geometry
    Assembly: Hypar.Elements.dll
    Syntax
    public struct Color : IEquatable<Color>

    Constructors

    Color(Double, Double, Double, Double)

    Create a color.

    Declaration
    [JsonConstructor]
    public Color(double red, double green, double blue, double alpha)
    Parameters
    Type Name Description
    System.Double red

    The red component.

    System.Double green

    The green component.

    System.Double blue

    The blue component.

    System.Double alpha

    The alpha component.

    Color(Color)

    Create an Elements Color from a System.Drawing.Color

    Declaration
    public Color(Color color)
    Parameters
    Type Name Description
    System.Drawing.Color color

    A System.Drawing.Color value.

    Color(String)

    Convert a hex code or an english name to a color.

    Declaration
    public Color(string hexOrName)
    Parameters
    Type Name Description
    System.String hexOrName

    The hex code (e.g. #F05C6D) or common color name (e.g. "Goldenrod") to turn into a color. (Recognized names are from the UNIX X11 named color values — see https://docs.microsoft.com/en-us/dotnet/api/system.windows.media.colors?view=windowsdesktop-6.0 for a complete listing.)

    Properties

    Alpha

    The alpha component of the color between 0.0 and 1.0.

    Declaration
    [JsonProperty("Alpha", Required = Required.Always)]
    [Range(0, 1)]
    public double Alpha { get; set; }
    Property Value
    Type Description
    System.Double

    Blue

    The blue component of the color between 0.0 and 1.0.

    Declaration
    [JsonProperty("Blue", Required = Required.Always)]
    [Range(0, 1)]
    public double Blue { get; set; }
    Property Value
    Type Description
    System.Double

    Green

    The green component of the color between 0.0 and 1.0.

    Declaration
    [JsonProperty("Green", Required = Required.Always)]
    [Range(0, 1)]
    public double Green { get; set; }
    Property Value
    Type Description
    System.Double

    Red

    The red component of the color between 0.0 and 1.0.

    Declaration
    [JsonProperty("Red", Required = Required.Always)]
    [Range(0, 1)]
    public double Red { get; set; }
    Property Value
    Type Description
    System.Double

    Methods

    Equals(Color)

    Is this color equal to the provided color?

    Declaration
    public bool Equals(Color other)
    Parameters
    Type Name Description
    Color other

    The color to test.

    Returns
    Type Description
    System.Boolean

    Returns true if the two colors are equal, otherwise false.

    Equals(Object)

    Is this color equal to the provided color?

    Declaration
    public override bool Equals(object obj)
    Parameters
    Type Name Description
    System.Object obj
    Returns
    Type Description
    System.Boolean
    Overrides
    System.ValueType.Equals(System.Object)

    GetHashCode()

    Get the hash code for this color.

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    System.Int32
    Overrides
    System.ValueType.GetHashCode()

    Lerp(Color, Double)

    Linearly interpolate between this color and the other color.

    Declaration
    public Color Lerp(Color other, double t)
    Parameters
    Type Name Description
    Color other

    The other color.

    System.Double t

    A value between 0.0 and 1.0.

    Returns
    Type Description
    Color

    LinearToSRGB(Double)

    Convert a linear color space component to a gamma color space value.

    Declaration
    public static double LinearToSRGB(double c)
    Parameters
    Type Name Description
    System.Double c

    The linear color component value.

    Returns
    Type Description
    System.Double

    A gamma color space component value.

    SRGBToLinear(Double)

    Convert a gamma color space component to a linear color space value.

    Declaration
    public static double SRGBToLinear(double c)
    Parameters
    Type Name Description
    System.Double c

    The gamma color component value.

    Returns
    Type Description
    System.Double

    A linear color space component value.

    ToArray(Boolean)

    Get the color's components as an array.

    Declaration
    public float[] ToArray(bool convertToLinearColorSpace = false)
    Parameters
    Type Name Description
    System.Boolean convertToLinearColorSpace
    Returns
    Type Description
    System.Single[]

    An array containing the color's components.

    ToString()

    Converts this color to a string.

    Declaration
    public override string ToString()
    Returns
    Type Description
    System.String

    Returns a string representation of the form "R: r, G: g, B: b, A: a".

    Overrides
    System.ValueType.ToString()

    Operators

    Addition(Color, Color)

    Add two colors. Resulting values will be clamped in the range of 0.0 to 1.0.

    Declaration
    public static Color operator +(Color a, Color b)
    Parameters
    Type Name Description
    Color a

    The first color.

    Color b

    The second color.

    Returns
    Type Description
    Color

    Equality(Color, Color)

    Are the two Colors equal?

    Declaration
    public static bool operator ==(Color a, Color b)
    Parameters
    Type Name Description
    Color a
    Color b
    Returns
    Type Description
    System.Boolean

    Implicit(String to Color)

    Automatically convert a hex code or an english name to a color.

    Declaration
    public static implicit operator Color(string hexOrName)
    Parameters
    Type Name Description
    System.String hexOrName

    The hex code (e.g. #F05C6D) or common color name (e.g. "Goldenrod") to turn into a color. (Recognized names are from the UNIX X11 named color values — see https://docs.microsoft.com/en-us/dotnet/api/system.windows.media.colors?view=windowsdesktop-6.0 for a complete listing.)

    Returns
    Type Description
    Color

    Implicit((Double R, Double G, Double B, Double A) to Color)

    Automatically convert a tuple (R,G,B,A) to a color.

    Declaration
    public static implicit operator Color((double R, double G, double B, double A) color)
    Parameters
    Type Name Description
    System.ValueTuple<System.Double, System.Double, System.Double, System.Double> color

    An (R,G,B,A) tuple of doubles.

    Returns
    Type Description
    Color

    Implicit((Double R, Double G, Double B) to Color)

    Automatically convert a tuple (R,G,B) to a color.

    Declaration
    public static implicit operator Color((double R, double G, double B) color)
    Parameters
    Type Name Description
    System.ValueTuple<System.Double, System.Double, System.Double> color

    An (R,G,B) tuple of doubles.

    Returns
    Type Description
    Color

    Inequality(Color, Color)

    Are the two Colors equal?

    Declaration
    public static bool operator !=(Color a, Color b)
    Parameters
    Type Name Description
    Color a
    Color b
    Returns
    Type Description
    System.Boolean

    Multiply(Color, Color)

    Multiply two colors. Resulting values will be clamped in the range of 0.0 to 1.0.

    Declaration
    public static Color operator *(Color a, Color b)
    Parameters
    Type Name Description
    Color a

    The first color.

    Color b

    The second color.

    Returns
    Type Description
    Color

    Multiply(Double, Color)

    Multiply a color and a scalar. Resulting values will be clamped in the range of 0.0 to 1.0.

    Declaration
    public static Color operator *(double t, Color a)
    Parameters
    Type Name Description
    System.Double t

    The scalar.

    Color a

    The color.

    Returns
    Type Description
    Color

    Implements

    System.IEquatable<T>