[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(IReader reader)
reader (IReader)

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

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

ChannelCount

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

Space

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

Indexers

this[]

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

Methods

Equals

#
public bool Equals(Color other)
other (Color)

Equals

#
public bool Equals(Colour other)
other (Colour)

Equals

#
public override bool Equals(object obj)
obj (object)
Object.Equals

FromCmy

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

FromCmyk

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

FromEto

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

FromGdi

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

FromHsl

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

FromHsp

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

FromHsv

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

FromLab

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

FromOklab

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

FromOklch

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

FromRgb

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

FromRgbLinear

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

FromSpecial

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

FromXyz

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

FromYxy

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

GetHashCode

#
public override int GetHashCode()
Explicit

IStorable.Store

#
void IStorable.Store(IWriter writer)
writer (IWriter)
Store

ToEto

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

ToNamedString

#
public string 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.

ToNamedString

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

ToString

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

WithAlpha

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

WithChannels

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

WithSpace

#
public Colour WithSpace(Space targetSpace)
Modify the space in which this colour is defined.
targetSpace (Space)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