Class Palette
A palette of colors.
Implements
Inherited Members
Namespace: SadRogue.Primitives
Assembly: TheSadRogue.Primitives.dll
Syntax
[DataContract]
public class Palette : IReadOnlyList<Color>, IReadOnlyCollection<Color>, IEnumerable<Color>, IEnumerable, IMatchable<Palette>
Constructors
View SourcePalette(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(int)
Creates a new palette with the specified amount of colors.
Declaration
public Palette(int colors)
Parameters
| Type | Name | Description |
|---|---|---|
| int | colors | The number of colors. |
Properties
View SourceCount
How many colors the palette has.
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| int |
this[int]
Gets or sets a color in the palette by index.
Declaration
public Color this[int index] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| int | 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 |
|---|---|
| int |
Methods
View SourceGetEnumerator()
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 |
|---|---|
| int | 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 |
|---|---|
| bool | 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(int, int)
Shifts a range of colors in the palette once to the left.
Declaration
public void ShiftLeft(int startingIndex, int count)
Parameters
| Type | Name | Description |
|---|---|---|
| int | startingIndex | The starting index in the palette. |
| int | 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(int, int)
Shifts a range of colors in the palette once to the right.
Declaration
public void ShiftRight(int startingIndex, int count)
Parameters
| Type | Name | Description |
|---|---|---|
| int | startingIndex | The starting index in the palette. |
| int | count | The amount of colors to shift from the starting index. |