Skip to content

ColorExtensions2 Class

Various extension methods to SadRogue.Primitives.Color class.

C#
public static class ColorExtensions2

Inheritance object

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.

C#
public static Dictionary<string, Color> ColorMappings

Creates an array of colors that includes the color and endingColor and steps of colors between them.

C#
public static Color[] LerpSteps(this Color color, Color endingColor, int steps)

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).

SadRogue.Primitives.Color[]
An array of colors.

Sets the color values based on HSL instead of RGB.

C#
public static Color SetHSL(this Color color, float h, float s, float l)

color SadRogue.Primitives.Color
The color to change.

h float
The hue amount.

s float
The saturation amount.

l float
The luminance amount.

SadRogue.Primitives.Color

Taken from http://www.easyrgb.com/index.php?X=MATH&amp;H=19#text19

Gets a random color.

C#
public static Color GetRandomColor(this Color color, Random random)

color SadRogue.Primitives.Color
The color object to start with. Will be overridden.

random Random
A random object to get numbers from.

SadRogue.Primitives.Color
A new color.

Gets a darker version of the color. R,G,B channels are * 0.25f.

C#
public static Color GetDark(this Color color)

color SadRogue.Primitives.Color
Object instance.

SadRogue.Primitives.Color
A darker color.

Gets a darker version of the color. R,G,B channels are * 0.50f.

C#
public static Color GetDarker(this Color color)

color SadRogue.Primitives.Color
Object instance.

SadRogue.Primitives.Color
A darker color.

Gets a darker version of the color. R,G,B channels are * 0.75f.

C#
public static Color GetDarkest(this Color color)

color SadRogue.Primitives.Color
Object instance.

SadRogue.Primitives.Color
A darker color.

Gets a brighter version of the color. R,G,B channels are * 1.25f.

C#
public static Color GetBright(this Color color)

color SadRogue.Primitives.Color
Object instance.

SadRogue.Primitives.Color
A darker color.

Gets a brighter version of the color. R,G,B channels are * 1.50f.

C#
public static Color GetBrighter(this Color color)

color SadRogue.Primitives.Color
Object instance.

SadRogue.Primitives.Color
A darker color.

Gets a brighter version of the color. R,G,B channels are * 1.75f.

C#
public static Color GetBrightest(this Color color)

color SadRogue.Primitives.Color
Object instance.

SadRogue.Primitives.Color
A darker color.

Returns a new Color using only the Red value of this color.

C#
public static Color RedOnly(this Color color)

color SadRogue.Primitives.Color
Object instance.

SadRogue.Primitives.Color
A color with only the red channel set.

Returns a new Color using only the Green value of this color.

C#
public static Color GreenOnly(this Color color)

color SadRogue.Primitives.Color
Object instance.

SadRogue.Primitives.Color
A color with only the green channel set.

Returns a new Color using only the Blue value of this color.

C#
public static Color BlueOnly(this Color color)

color SadRogue.Primitives.Color
Object instance.

SadRogue.Primitives.Color
A color with only the blue channel set.

Returns a new Color using only the Alpha value of this color.

C#
public static Color AlphaOnly(this Color color)

color SadRogue.Primitives.Color
Object instance.

SadRogue.Primitives.Color
A color with only the alpha channel set.

Returns a new color with the red channel set to 0.

C#
public static Color ClearRed(this Color color)

color SadRogue.Primitives.Color
Object instance.

SadRogue.Primitives.Color
A color with the red channel cleared.

Returns a new color with the green channel set to 0.

C#
public static Color ClearGreen(this Color color)

color SadRogue.Primitives.Color
Object instance.

SadRogue.Primitives.Color
A color with the green channel cleared.

Returns a new color with the blue channel set to 0.

C#
public static Color ClearBlue(this Color color)

color SadRogue.Primitives.Color
Object instance.

SadRogue.Primitives.Color
A color with the blue channel cleared.

Returns a new color with the alpha channel set to 0.

C#
public static Color ClearAlpha(this Color color)

color SadRogue.Primitives.Color
Object instance.

SadRogue.Primitives.Color
A color with the alpha channel cleared.

Returns a new color with the red channel set to 255.

C#
public static Color FillRed(this Color color)

color SadRogue.Primitives.Color
Object instance.

SadRogue.Primitives.Color
A color with the red channel fully set.

Returns a new color with the green channel set to 255.

C#
public static Color FillGreen(this Color color)

color SadRogue.Primitives.Color
Object instance.

SadRogue.Primitives.Color
A color with the green channel fully set.

Returns a new color with the blue channel set to 255.

C#
public static Color FillBlue(this Color color)

color SadRogue.Primitives.Color
Object instance.

SadRogue.Primitives.Color
A color with the blue channel fully set.

Returns a new color with the alpha channel set to 255.

C#
public static Color FillAlpha(this Color color)

color SadRogue.Primitives.Color
Object instance.

SadRogue.Primitives.Color
A color with the alpha channel fully set.

Returns a new color with the red channel set to the specified value.

C#
public static Color SetRed(this Color color, byte value)

color SadRogue.Primitives.Color
Object instance.

value byte
The new value for the red channel.

SadRogue.Primitives.Color
A color with the red channel altered.

Returns a new color with the green channel set to the specified value.

C#
public static Color SetGreen(this Color color, byte value)

color SadRogue.Primitives.Color
Object instance.

value byte
The new value for the green channel.

SadRogue.Primitives.Color
A color with the green channel altered.

Returns a new color with the blue channel set to the specified value.

C#
public static Color SetBlue(this Color color, byte value)

color SadRogue.Primitives.Color
Object instance.

value byte
The new value for the blue channel.

SadRogue.Primitives.Color
A color with the blue channel altered.

Returns a new color with the alpha channel set to the specified value.

C#
public static Color SetAlpha(this Color color, byte value)

color SadRogue.Primitives.Color
Object instance.

value byte
The new value for the alpha channel.

SadRogue.Primitives.Color
A color with the alpha channel altered.

Gets the luma of an existing color.

C#
public static float GetLuma(this Color color)

color SadRogue.Primitives.Color
The color to calculate the luma from.

float
A value based on this code: (color.R + color.R + color.B + color.G + color.G + color.G) / 6f

Gets the brightness of a color.

C#
public static float GetBrightness(this Color color)

color SadRogue.Primitives.Color
The color to process.

float
The brightness value.

Taken from the mono source code.

Gets the saturation of a color.

C#
public static float GetSaturation(this Color color)

color SadRogue.Primitives.Color
The color to process.

float
The saturation value.

Taken from the mono source code.

Gets the hue of a color.

C#
public static float GetHue(this Color color)

color SadRogue.Primitives.Color
The color to process.

float
The hue value.

Taken from the mono source code.

Converts a color to the format used by ParseCommandRecolor command.

C#
public static string ToParser(this Color color)

color SadRogue.Primitives.Color
The color to convert.

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.

C#
public static Color FromParser(this Color color, string value, out bool keepR, out bool keepG, out bool keepB, out bool keepA, out bool useDefault)

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.

SadRogue.Primitives.Color

Searches ColorMappings for a defined color.

C#
public static Color FromName(string name)

name string
The name of a color.

SadRogue.Primitives.Color
A color.

Searches ColorMappings for a defined color. If color is not defined, the color specified by defaultColor is returned.

C#
public static Color FromName(string name, Color defaultColor)

name string
The name of a color.

defaultColor SadRogue.Primitives.Color
Fallback color.

SadRogue.Primitives.Color
A color.

Creates a ColoredString object using the current gradient.

C#
public static ColoredString ToColoredString(this Gradient gradient, string text)

gradient SadRogue.Primitives.Gradient
The gradient to work with.

text string
The text to use for the colored string.

ColoredString
A new colored string object.