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