Class Palette
A palette of colors.
Implements
Namespace: SadRogue.Primitives
Assembly: TheSadRogue.Primitives.dll
Syntax
public class Palette : Object, IReadOnlyList<Color>, IEnumerable<Color>, IEnumerable, IReadOnlyCollection<Color>, IMatchable<Palette>
Constructors
Palette(IEnumerable<Color>)
Creates a new palette of colors from a list of existing colors.
Declaration
public Palette(IEnumerable<Color> colors)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<Color> | colors | The list of colors this palette is made from. |
Palette(Int32)
Creates a new palette with the specified amount of colors.
Declaration
public Palette(int colors)
Parameters
Type | Name | Description |
---|---|---|
Int32 | colors | The number of colors. |
Properties
Count
How many colors the palette has.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
Int32 |
Item[Int32]
Gets or sets a color in the palette by index.
Declaration
public Color this[int index] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | Index of the color. |
Property Value
Type | Description |
---|---|
Color | A color. |
Length
How many colors the palette has.
Declaration
public int Length { get; }
Property Value
Type | Description |
---|---|
Int32 |
Methods
GetEnumerator()
Gets the list of colors in the palette.
Declaration
public IEnumerator<Color> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<Color> | The colors in the palette. |
GetNearest(Color)
Gets the closest color in the palette to the provided color.
Declaration
public Color GetNearest(Color color)
Parameters
Type | Name | Description |
---|---|---|
Color | color | The color to find. |
Returns
Type | Description |
---|---|
Color | The closest matching color. |
GetNearestIndex(Color)
Gets the index of the closest color in the palette to the provided color.
Declaration
public int GetNearestIndex(Color color)
Parameters
Type | Name | Description |
---|---|---|
Color | color | The color to find. |
Returns
Type | Description |
---|---|
Int32 | The palette index of the closest color. |
Matches(Palette)
Returns true if the two palettes hold identical colors in the same order.
Declaration
public bool Matches(Palette other)
Parameters
Type | Name | Description |
---|---|---|
Palette | other |
Returns
Type | Description |
---|---|
Boolean | True if the two palettes hold identical colors in the same order; false otherwise. |
ShiftLeft()
Shifts the entire palette once to the left.
Declaration
public void ShiftLeft()
ShiftLeft(Int32, Int32)
Shifts a range of colors in the palette once to the left.
Declaration
public void ShiftLeft(int startingIndex, int count)
Parameters
Type | Name | Description |
---|---|---|
Int32 | startingIndex | The starting index in the palette. |
Int32 | count | The amount of colors to shift from the starting index. |
ShiftRight()
Shifts the entire palette once to the right.
Declaration
public void ShiftRight()
ShiftRight(Int32, Int32)
Shifts a range of colors in the palette once to the right.
Declaration
public void ShiftRight(int startingIndex, int count)
Parameters
Type | Name | Description |
---|---|---|
Int32 | startingIndex | The starting index in the palette. |
Int32 | count | The amount of colors to shift from the starting index. |