Class ColorExtensions2
Various extension methods to Color class.
Inherited Members
Namespace: SadRogue.Primitives
Assembly: SadConsole.dll
Syntax
public static class ColorExtensions2
Fields
ColorMappings
Custom color mappings for the FromName(string) and FromParser(Color, string, out bool, out bool, out bool, out bool, out bool) methods. Key names should be lowercase.
Declaration
public static Dictionary<string, Color> ColorMappings
Field Value
| Type | Description |
|---|---|
| Dictionary<string, Color> |
Methods
AlphaOnly(Color)
Returns a new Color using only the Alpha value of this color.
Declaration
public static Color AlphaOnly(this Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | Object instance. |
Returns
| Type | Description |
|---|---|
| Color | A color with only the alpha channel set. |
BlueOnly(Color)
Returns a new Color using only the Blue value of this color.
Declaration
public static Color BlueOnly(this Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | Object instance. |
Returns
| Type | Description |
|---|---|
| Color | A color with only the blue channel set. |
ClearAlpha(Color)
Returns a new color with the alpha channel set to 0.
Declaration
public static Color ClearAlpha(this Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | Object instance. |
Returns
| Type | Description |
|---|---|
| Color | A color with the alpha channel cleared. |
ClearBlue(Color)
Returns a new color with the blue channel set to 0.
Declaration
public static Color ClearBlue(this Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | Object instance. |
Returns
| Type | Description |
|---|---|
| Color | A color with the blue channel cleared. |
ClearGreen(Color)
Returns a new color with the green channel set to 0.
Declaration
public static Color ClearGreen(this Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | Object instance. |
Returns
| Type | Description |
|---|---|
| Color | A color with the green channel cleared. |
ClearRed(Color)
Returns a new color with the red channel set to 0.
Declaration
public static Color ClearRed(this Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | Object instance. |
Returns
| Type | Description |
|---|---|
| Color | A color with the red channel cleared. |
FillAlpha(Color)
Returns a new color with the alpha channel set to 255.
Declaration
public static Color FillAlpha(this Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | Object instance. |
Returns
| Type | Description |
|---|---|
| Color | A color with the alpha channel fully set. |
FillBlue(Color)
Returns a new color with the blue channel set to 255.
Declaration
public static Color FillBlue(this Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | Object instance. |
Returns
| Type | Description |
|---|---|
| Color | A color with the blue channel fully set. |
FillGreen(Color)
Returns a new color with the green channel set to 255.
Declaration
public static Color FillGreen(this Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | Object instance. |
Returns
| Type | Description |
|---|---|
| Color | A color with the green channel fully set. |
FillRed(Color)
Returns a new color with the red channel set to 255.
Declaration
public static Color FillRed(this Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | Object instance. |
Returns
| Type | Description |
|---|---|
| Color | A color with the red channel fully set. |
FromName(string)
Searches ColorMappings for a defined color.
Declaration
public static Color FromName(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name of a color. |
Returns
| Type | Description |
|---|---|
| Color | A color. |
FromName(string, Color)
Searches ColorMappings for a defined color. If color is not defined, the color specified by defaultColor is returned.
Declaration
public static Color FromName(string name, Color defaultColor)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name of a color. |
| Color | defaultColor | Fallback color. |
Returns
| Type | Description |
|---|---|
| Color | A color. |
FromParser(Color, string, out bool, out bool, out bool, out bool, out bool)
Gets a color in the format of ParseCommandRecolor.
Declaration
public static Color FromParser(this Color color, string value, out bool keepR, out bool keepG, out bool keepB, out bool keepA, out bool useDefault)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | The color to use as a base. |
| string | value | The string parser color command. |
| bool | keepR | Indicates that command wanted to keep the Red color channel. |
| bool | keepG | Indicates that command wanted to keep the Green color channel. |
| bool | keepB | Indicates that command wanted to keep the Blue color channel. |
| bool | keepA | Indicates that command wanted to keep the Alpha color channel. |
| bool | useDefault | Indicates that command wanted to use the default values passed. |
Returns
| Type | Description |
|---|---|
| Color |
GetBright(Color)
Gets a brighter version of the color. R,G,B channels are * 1.25f.
Declaration
public static Color GetBright(this Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | Object instance. |
Returns
| Type | Description |
|---|---|
| Color | A darker color. |
GetBrighter(Color)
Gets a brighter version of the color. R,G,B channels are * 1.50f.
Declaration
public static Color GetBrighter(this Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | Object instance. |
Returns
| Type | Description |
|---|---|
| Color | A darker color. |
GetBrightest(Color)
Gets a brighter version of the color. R,G,B channels are * 1.75f.
Declaration
public static Color GetBrightest(this Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | Object instance. |
Returns
| Type | Description |
|---|---|
| Color | A darker color. |
GetBrightness(Color)
Gets the brightness of a color.
Declaration
public static float GetBrightness(this Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | The color to process. |
Returns
| Type | Description |
|---|---|
| float | The brightness value. |
Remarks
Taken from the mono source code.
GetDark(Color)
Gets a darker version of the color. R,G,B channels are * 0.25f.
Declaration
public static Color GetDark(this Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | Object instance. |
Returns
| Type | Description |
|---|---|
| Color | A darker color. |
GetDarker(Color)
Gets a darker version of the color. R,G,B channels are * 0.50f.
Declaration
public static Color GetDarker(this Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | Object instance. |
Returns
| Type | Description |
|---|---|
| Color | A darker color. |
GetDarkest(Color)
Gets a darker version of the color. R,G,B channels are * 0.75f.
Declaration
public static Color GetDarkest(this Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | Object instance. |
Returns
| Type | Description |
|---|---|
| Color | A darker color. |
GetHue(Color)
Gets the hue of a color.
Declaration
public static float GetHue(this Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | The color to process. |
Returns
| Type | Description |
|---|---|
| float | The hue value. |
Remarks
Taken from the mono source code.
GetLuma(Color)
Gets the luma of an existing color.
Declaration
public static float GetLuma(this Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | The color to calculate the luma from. |
Returns
| Type | Description |
|---|---|
| float | A value based on this code: (color.R + color.R + color.B + color.G + color.G + color.G) / 6f |
GetRandomColor(Color, Random)
Gets a random color.
Declaration
public static Color GetRandomColor(this Color color, Random random)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | The color object to start with. Will be overridden. |
| Random | random | A random object to get numbers from. |
Returns
| Type | Description |
|---|---|
| Color | A new color. |
GetSaturation(Color)
Gets the saturation of a color.
Declaration
public static float GetSaturation(this Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | The color to process. |
Returns
| Type | Description |
|---|---|
| float | The saturation value. |
Remarks
Taken from the mono source code.
GreenOnly(Color)
Returns a new Color using only the Green value of this color.
Declaration
public static Color GreenOnly(this Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | Object instance. |
Returns
| Type | Description |
|---|---|
| Color | A color with only the green channel set. |
LerpSteps(Color, Color, int)
Creates an array of colors that includes the color and endingColor and steps of colors between them.
Declaration
public static Color[] LerpSteps(this Color color, Color endingColor, int steps)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | The starting color which will be at index 0 in the array. |
| Color | endingColor | The ending color which will be at index |
| int | steps | The gradient steps in the array which uses Lerp(Color, Color, float). |
Returns
| Type | Description |
|---|---|
| Color[] | An array of colors. |
RedOnly(Color)
Returns a new Color using only the Red value of this color.
Declaration
public static Color RedOnly(this Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | Object instance. |
Returns
| Type | Description |
|---|---|
| Color | A color with only the red channel set. |
SetAlpha(Color, byte)
Returns a new color with the alpha channel set to the specified value.
Declaration
public static Color SetAlpha(this Color color, byte value)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | Object instance. |
| byte | value | The new value for the alpha channel. |
Returns
| Type | Description |
|---|---|
| Color | A color with the alpha channel altered. |
SetBlue(Color, byte)
Returns a new color with the blue channel set to the specified value.
Declaration
public static Color SetBlue(this Color color, byte value)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | Object instance. |
| byte | value | The new value for the blue channel. |
Returns
| Type | Description |
|---|---|
| Color | A color with the blue channel altered. |
SetGreen(Color, byte)
Returns a new color with the green channel set to the specified value.
Declaration
public static Color SetGreen(this Color color, byte value)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | Object instance. |
| byte | value | The new value for the green channel. |
Returns
| Type | Description |
|---|---|
| Color | A color with the green channel altered. |
SetHSL(Color, float, float, float)
Sets the color values based on HSL instead of RGB.
Declaration
public static Color SetHSL(this Color color, float h, float s, float l)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | The color to change. |
| float | h | The hue amount. |
| float | s | The saturation amount. |
| float | l | The luminance amount. |
Returns
| Type | Description |
|---|---|
| Color |
Remarks
Taken from http://www.easyrgb.com/index.php?X=MATH&H=19#text19
SetRed(Color, byte)
Returns a new color with the red channel set to the specified value.
Declaration
public static Color SetRed(this Color color, byte value)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | Object instance. |
| byte | value | The new value for the red channel. |
Returns
| Type | Description |
|---|---|
| Color | A color with the red channel altered. |
ToColoredString(Gradient, string)
Creates a ColoredString object using the current gradient.
Declaration
public static ColoredString ToColoredString(this Gradient gradient, string text)
Parameters
| Type | Name | Description |
|---|---|---|
| Gradient | gradient | The gradient to work with. |
| string | text | The text to use for the colored string. |
Returns
| Type | Description |
|---|---|
| ColoredString | A new colored string object. |
ToParser(Color)
Converts a color to the format used by ParseCommandRecolor command.
Declaration
public static string ToParser(this Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | The color to convert. |
Returns
| Type | Description |
|---|---|
| string | A string in this format R,G,B,A so for Green you would get .
|