[IoId("00000000-c3b4-48fe-9367-bb4402cf6471")] public sealed class Colour : IStorable, IEquatable<Colour>
Provides a way to store colours using a variety of spaces using high-precision mathematics. This is the class Grasshopper uses internally to store colours. Rhino, Eto, and .NET have their own colour types (usually ColorRGBA, Color, and Color, but there are many more), so you may need to convert to and from those types to Colour on a per-case basis.

Constructors

Colour

#
public Colour(
reader
)

Fields

NameCMY

#
public const string NameCMY = "CMY"

NameCMYK

#
public const string NameCMYK = "CMYK"

NameHSL

#
public const string NameHSL = "HSL"

NameHSP

#
public const string NameHSP = "HSP"

NameHSV

#
public const string NameHSV = "HSV"

NameIcon

#
public const string NameIcon = "Icon"

NameLAB

#
public const string NameLAB = "Lab"

NameOKLAB

#
public const string NameOKLAB = "Oklab"

NameRGB

#
public const string NameRGB = "RGB"

NameRGBLinear

#
public const string NameRGBLinear = "linRGB"

NameSRGB

#
public const string NameSRGB = "sRGB"

NameXYZ

#
public const string NameXYZ = "XYZ"

NameYXY

#
public const string NameYXY = "Yxy"

OfficialNameCMY

#
public const string OfficialNameCMY = "CMY"

OfficialNameCMYK

#
public const string OfficialNameCMYK = "CMYK"

OfficialNameHSL

#
public const string OfficialNameHSL = "HSL"

OfficialNameHSP

#
public const string OfficialNameHSP = "H*SP"

OfficialNameHSV

#
public const string OfficialNameHSV = "HSV"

OfficialNameIcon

#
public const string OfficialNameIcon = "G2-Icon"

OfficialNameLAB

#
public const string OfficialNameLAB = "CIE-L*a*b*"

OfficialNameOKLAB

#
public const string OfficialNameOKLAB = "Oklab"

OfficialNameRGB

#
public const string OfficialNameRGB = "RGB"

OfficialNameRGBLinear

#
public const string OfficialNameRGBLinear = "Linear RGB"

OfficialNameSRGB

#
public const string OfficialNameSRGB = "Standard RGB"

OfficialNameXYZ

#
public const string OfficialNameXYZ = "CIE-XYZ"

OfficialNameYXY

#
public const string OfficialNameYXY = "CIE-Yxy"

Properties

Alpha

#
Gets the alpha channel or transparency for this colour.
public float Alpha { get; }

ChannelCount

#
Gets the number of channels.
public int ChannelCount { get; }

Space

#
Gets the model this colour is defined in.
public Space Space { get; }

Indexers

this[]

#
Gets the channel value with the given index.
public double this[
index
Channel index.
] { get; }

Methods

Equals

#
public bool Equals(
Color
other
)

Equals

#
public bool Equals(
other
)

Equals

#
public override bool Equals(
obj
)
Object.Equals

FromCmy

#
Create a new CMY colour.
public static Colour FromCmy(
cyan,
magenta,
yellow,
alpha = 1
)

FromCmyk

#
Create a new CMYK colour.
public static Colour FromCmyk(
cyan,
magenta,
yellow,
key,
alpha = 1
)

FromEto

#
Create a new sRGB or Special colour based on an Color.
public static Colour FromEto(
Color
colour
)

FromGdi

#
Create a new sRGB or Special colour based on a Color.
public static Colour FromGdi(
Color
colour
)

FromHsl

#
Create a new HSL colour.
public static Colour FromHsl(
hue,
saturation,
luminance,
alpha = 1
)

FromHsp

#
Create a new H*SP colour.
public static Colour FromHsp(
hue,
saturation,
luminance,
alpha = 1
)

FromHsv

#
Create a new HSV (HSB) colour.
public static Colour FromHsv(
hue,
saturation,
value,
alpha = 1
)

FromLab

#
Create a new Cie Yxy colour.
public static Colour FromLab(
L,
a,
b,
alpha = 1
)

FromOklab

#
Create a new Oklab colour.
public static Colour FromOklab(
L,
Perceptual lightness, 0 to 1.
a,
Green-red opposition channel.
b,
Blue-yellow opposition channel.
alpha = 1
Opacity.
)

FromOklch

#
Create a new Oklab colour from its polar Oklch form.
public static Colour FromOklch(
L,
Perceptual lightness, 0 to 1.
chroma,
Chroma, the distance from the neutral axis.
hue,
Hue in degrees.
alpha = 1
Opacity.
)

FromRgb

#
Create a new sRGB colour.
public static Colour FromRgb(
red,
green,
blue,
alpha = 1
)

FromRgbLinear

#
Create a new linear RGB colour.
public static Colour FromRgbLinear(
red,
green,
blue,
alpha = 1
)

FromSpecial

#
Create a new Icon colour from a special hint.
public static Colour FromSpecial(
specialColour
)

FromXyz

#
Create a new Cie XYZ colour.
public static Colour FromXyz(
x,
y,
z,
alpha = 1
)

FromYxy

#
Create a new Cie Yxy colour.
public static Colour FromYxy(
Y,
x,
y,
alpha = 1
)

GetHashCode

#
public override int GetHashCode()
Explicit

IStorable.Store

#
void IStorable.Store(
writer
)
Store

ToEto

#
Convert this colour to an Color.
public Color ToEto()

ToNamedString

#
Returns the name of this colour, or a description of its channels. The name is only returned if this colour is defined in sRGB.
public string ToNamedString()

ToNamedString

#
Returns the name of this colour, or a description of its channels. The name is only returned if this colour is defined in sRGB.
public string ToNamedString(
params NamedPalette[]
palettes
)

ToString

#
Returns the fully qualified type name of this instance.
public override string ToString()
Object.ToString

WithAlpha

#
Modify the alpha of this colour.
public Colour WithAlpha(
newAlpha
)

WithChannels

#
Modify the channels of this colour.
public Colour WithChannels(
params double[]
channels
)

WithSpace

#
Modify the space in which this colour is defined.
public Colour WithSpace(
targetSpace
New space.
)

Operators

OperationResultDescription
Colour+ColourColourAdd two colours in the Linear RGB space.
Colour+doubleColourAdd two colours in the Linear RGB space.
double+ColourColourAdd two colours in the Linear RGB space.
Colour/ColourColourDivide two colours in the Linear RGB space, which is actually the Screen blending mode.
Colour/doubleColourDivide two colours in the Linear RGB space, which is actually the Screen blending mode.
double/ColourColourDivide two colours in the Linear RGB space, which is actually the Screen blending mode.
Colour==ColourboolTest for equality.
Colour!=ColourboolTest for inequality.
Colour*ColourColourMultiply two colours in the Linear RGB space.
Colour*doubleColourMultiply two colours in the Linear RGB space.
double*ColourColourMultiply two colours in the Linear RGB space.
Colour-ColourColourSubtract two colours in the Linear RGB space.
Colour-doubleColourSubtract two colours in the Linear RGB space.
double-ColourColourSubtract two colours in the Linear RGB space.
-ColourColourNegate a colour in the Linear RGB space.

Convertors

OperationResultDescription
implicitColorColour
implicitColorColour