ColourExtensionMethods

public static class ColourExtensionMethods
Extension methods for Eto.Drawing.Colour

Methods

Add two colours.
public static Color Add(
this Color
colour,
Base colour.
Color
overlay
Overlay colour.
)
Added colour.

AdjustLevel

#Example
There are four categories of special colour (Analysis, input, output, symbolic) which have four brighnesses in them (XxxxDark, Xxxx, XxxxLight, XxxxShine). This method will change those brightnesses depending on a level adjustment.
public static SpecialColour AdjustLevel(
colour,
level
)
Clip the channels of a colour to the 0~1 range.
public static Color Clip(
this Color
colour
Colour to clip.
)
Clipped colour.

Composite

#Example
Create a new colour which acts as the composite of a background and a foreground colour.
public static Color Composite(
this Color
bottom,
Bottom colour.
Color
top
Top colour.
)
Composited colour.

Contrast

#Example
Create a contrasting colour useful for foreground/background distinction. Contrast colours retain hue but will change luminance.
public static Color Contrast(
this Color
colour,
Base colour.
contrast = 0.8
Contrast amount (0 to 1).
)
Associated contrast colour.

Darken

#Example
Decrease the luminance of a colour.
public static Color Darken(
this Color
colour,
Colour to start with.
factor
Darkening factor.
)
Darkened colour.

Desaturate

#Example
Desaturate a colour by moving its channels to greyscale values.
public static Color Desaturate(
this Color
colour,
Colour to desaturate.
amount,
Desaturation amount. 0=original colour, 1=pure grey.
metric = LuminanceMetric.YCbCrGammaAdjusted
Metric to use.
)
Fade a colour to transparency.
public static Color Fade(
this Color
colour,
Base colour.
t0,
Value at which colour becomes completely transparent.
t1,
Value at which colour remains fixed.
t
Sampling value.
)
Faded colour.
Return a gamma-reverted version of this colour. By reverting the gamma, a gamma-adjusted colour is restored into standard sRGB space.
public static Color Gamma(
this Color
colour,
Colour to revert.
factor = 2.2
Gamma exponent.
)
Gamma reverted version.

Gamma

#
Standard sRGB implementation of reverse gamma adjustment.
public static float Gamma(
value,
Value to adjust.
factor
Gamma exponent. Typical values range from 2.0 to 2.4, but values in between one and two may yield a weak gamma effect worth having.
)
Adjusted value.

GetHue

#Example
Gets the hue component (0~360) of a colour.
public static float GetHue(
this Color
colour
)

GetLuminance

#Example
Compute the luminance of a colour.
public static float GetLuminance(
this Color
colour,
Colour
metric
Metric to use.
)
Luminance of colour (0.0 to 1.0)

GetLuminance

#Example
Compute the perceived luminance of a colour using non-linear HSP weighting.
public static float GetLuminance(
this Color
colour
Colour.
)
Luminance of colour (0.0 to 1.0)

GetSaturation

#Example
Gets the saturation component (0~1) of a colour, as defined by the HSB colour model.
public static float GetSaturation(
this Color
colour
)

Invert

#Example
Create a negative colour. The alpha channel is not inverted.
public static Color Invert(
this Color
colour,
Base colour.
maintainLuminance
If true, the inversion happens in HSL space, rather than RGB space.
)
Negative colour.

IsDarkBackground

#Example
Determines whether a colour qualifies as a dark one, meaning that it requires foreground objects to be of a bright colour.
public static bool IsDarkBackground(
this Color
colour
)

Lighten

#Example
Increase the luminance of a colour.
public static Color Lighten(
this Color
colour,
Colour to start with.
factor
Lightening factor.
)
Lightened colour.

MoveTo

#Example
Create colour in between this colour and some target colour.
public static Color MoveTo(
this Color
colour,
Base colour.
Color
target,
Target colour.
factor,
Motion factor.
moveAlpha = true
If true, alpha channel will also be moved.
)
Moved colour.

Multiply

#Example
Multiply two colours. This has the effect of looking at the bottom colour through a piece of coloured glass.
public static Color Multiply(
this Color
colour,
Base colour.
Color
overlay
Overlay colour.
)
Multiplied colour.

Multiply

#Example
Multiply a colour.
public static Color Multiply(
this Color
colour,
Base colour.
factor
Multiplication factor.
)
Multiplied colour.

MultiplyLinear

#Example
Multiply two colours in LinearRGB. This has the effect of looking at the bottom colour through a piece of coloured glass.
public static Color MultiplyLinear(
this Color
colour,
Base colour.
Color
overlay
Overlay colour.
)
Multiplied colour.

Offset

#Example
Add a fixed value to all the channels in a colour.
public static Color Offset(
this Color
colour,
Base colour.
amount
Amount to add to each colour channel.
)
Offsetted colour.

Offset

#Example
Add a fixed value to all the channels in a colour.
public static Color Offset(
this Color
colour,
Base colour.
amountRed,
Amount to add to the red channel.
amountGreen,
Amount to add to the green channel.
amountBlue
Amount to add to the blue channel.
)
Offsetted colour.

Palette

#Example
Gets the pair of colours associated with the given process state.
public static (Color back, Color fore) Palette(
this ProcessState
state
)

PickLeastAlike

#Example
Pick a colour out of a palette which is the furthest away from other colours.
public static Color PickLeastAlike(
this Color[]
palette,
Palette to pick from.
IEnumerable<Color>
colours
Palette to compare against.
)
Colour in 'palette' which is the least like any colour in 'colours'.

Resolve

#Example
Resolve a colour based on some context.
public static Color Resolve(
colour,
Colour to resolve.
Color
background,
Background. If fully transparent, the OS control background will be substituted.
palette = null
Palette for resolving user-settable colours. If omitted, the standard Grasshopper palette will be substituted.
)

Rgb_CubeGamma

#Example
Mapping function from colours to the gamma adjusted (exponent = 2.4) RGB cube.
public static void Rgb_CubeGamma(
this Color
colour,
Colour to map.
out double
x,
X coordinate.
out double
y,
Y coordinate.
out double
z
Z coordinate.
)

Rgb_CubeSquare

#Example
Mapping function from colours to the gamma adjusted (exponent = 2.0) RGB cube.
public static void Rgb_CubeSquare(
this Color
colour,
Colour to map.
out double
x,
X coordinate.
out double
y,
Y coordinate.
out double
z
Z coordinate.
)

Rgb_CubeStandard

#Example
Mapping function from colours to the sRGB cube.
public static void Rgb_CubeStandard(
this Color
colour,
Colour to map.
out double
x,
X coordinate.
out double
y,
Y coordinate.
out double
z
Z coordinate.
)

Rgb_CylinderHsl

#Example
Mapping function from colours to the HSL cylinder.
public static void Rgb_CylinderHsl(
this Color
colour,
Colour to map.
out double
x,
X coordinate.
out double
y,
Y coordinate.
out double
z
Z coordinate.
)

Rgb_CylinderHsp

#Example
Mapping function from colours to the HSP* (perceived luminance) cylinder.
public static void Rgb_CylinderHsp(
this Color
colour,
Colour to map.
out double
x,
X coordinate.
out double
y,
Y coordinate.
out double
z
Z coordinate.
)

Rgb_CylinderHsv

#Example
Mapping function from colours to the HSV cylinder.
public static void Rgb_CylinderHsv(
this Color
colour,
Colour to map.
out double
x,
X coordinate.
out double
y,
Y coordinate.
out double
z
Z coordinate.
)

Rgb_Sinusoidal

#Example
Mapping function from colours to the Hsl sinusoidal space.

The projection space is a vertical half sine-wave revolved around the world Z axis. Bottom tip (black) resides at (0,0,-1) while the upper tip (white) can be found at (0,0,+1). The central axis from black to white contains all the greyscale values. Luminance is gamma adjusted and mapped along the vertical axis, hue is mapped around the vertical axis and saturation is mapped to an offset from the vertical axis. The offset is the product of the normalised saturation and the sine of the gamma-adjusted luminance.

public static void Rgb_Sinusoidal(
this Color
colour,
Colour to map.
out double
x,
X coordinate.
out double
y,
Y coordinate.
out double
z
Z coordinate.
)
Round a colour to 1/1000th accuracy in each channel.
public static Color Round(
this Color
colour
Colour to round.
)
Rounded colour.

SetBrightness

#Example
Set the luminance of a colour. This method uses HSV luminance metric.
public static Color SetBrightness(
this Color
colour,
Colour to modify.
brightness
New luminance (0.0~1.0 range).
)
Modified colour.

SetHue

#Example
Set the hue of a colour.
public static Color SetHue(
this Color
colour,
Colour to modify.
hue
New hue (0~360 range).
)
Modified colour.

SetLuminance

#Example
Set the luminance of a colour. This method uses a custom metric and an iterative process.
public static Color SetLuminance(
this Color
colour,
Colour to modify.
luminance,
New luminance (0.0~1.0 range).
metric
specific metric to use.
)
Modified colour.

SetLuminance

#Example
Set the luminance of a colour.
public static ColorHSL SetLuminance(
this ColorHSL
colour,
Colour to modify.
luminance,
New luminance (0.0~1.0 range).
metric
specific metric to use.
)
Modified colour.

SetSaturation

#Example
Set the saturation of a colour. This method uses HSV saturation metric.
public static Color SetSaturation(
this Color
colour,
Colour to modify.
saturation
New saturation (0.0~1.0 range).
)
Modified colour.

Sinusoidal_Rgb

#
Perform a reverse mapping from sinusoidal coordinates into sRGB coordinates. This conversion may be lossy if the coordinates reside outside the sinusoidal revolved volume.
public static Color Sinusoidal_Rgb()

ToBitmap

#Example
Create a bitmap filled with this colour.
public static Bitmap ToBitmap(
this Color
color,
Colour to fill.
width,
Width of bitmap.
height
Height of bitmap.
)
Single colour bitmap.
Convert a GDI+ colour into an Eto colour.
public static Color ToEto(
this Color
color
Color to convert.
)
Eto colour.
Gets the actual ARGB colour which hints at a special colour.
public static Color ToEto(
colour
)
Convert an eto colour into a GDI colour.
public static Color ToGdi(
this Color
color
Color to convert.
)
Gdi colour.

ToName

#Example
Return the name of the colour space without any whitespace or funky characters
public static string ToName(
this Space
space
)

ToName

#Example
Return the name of the colour space without any whitespace or funky characters
public static string ToName(
this Space3
space
)

ToOfficialName

#Example
Return the official name of a colour space including funky characters and whitespace.
public static string ToOfficialName(
this Space
space
)

ToOfficialName

#Example
Return the official name of a colour space including funky characters and whitespace.
public static string ToOfficialName(
this Space3
space
)

ToUiColour

#Example
Convert a colour so it will be displayed correctly in the UI. This involves optionally removing all alpha data as well as resolving special colours to their stand-in shades.
public static Color ToUiColour(
this Color
colour,
Colour to modify.
removeAlpha = true
If true, the alpha channel is stripped.
)
Colour suitable for display in the UI.

TryMatchEtoColorName

#Example
Try to find the named colour in Eto.Drawing.Colors which matches this colour. The pure name is returned, without the 'Eto' or the 'Drawing' or the 'Colors'. This method is fairly slow.
public static bool TryMatchEtoColorName(
this Color
colour,
Colour to test.
out string
name
Name, if successful.
)
True if a name was found.

TryParseSpecialColour

#Example
Test whether a colour is one of the special colour codes.
public static SpecialColour TryParseSpecialColour(
this Color
colour
Colour to test.
)
Special colour identifier if any.

UiColour

#Example
Gets a stand-in colour for the given special colour.
public static Color UiColour(
colour
)

UiInfo

#Example
Gets a description suitable for use in the UI for a given special colour.
public static string UiInfo(
colour
)

UiName

#Example
Gets a name suitable for use in the UI for a given special colour.
public static string UiName(
colour
)

Ungamma

#Example
Return a gamma-adjusted version of this colour. By adjusting the gamma, the colour is moved into a space where linear blending is more natural.
public static Color Ungamma(
this Color
colour,
Colour to adjust.
factor = 2.2
Gamma exponent.
)
Gamma adjusted version.

Ungamma

#
Apply a specific gamma function to a colour channel value.
public static float Ungamma(
value,
Value to adjust.
factor
Gamma exponent. Typical values range from 2.0 to 2.4, but values in between one and two may yield a weak gamma effect worth having.
)
Adjusted value.
Set the alpha channel of a colour.
public static Color WithA(
this Color
colour,
Colour to modify.
alpha
New alpha value.
)
Modified colour.