Table of Contents

Class ColorGradient

Namespace
Artemis.Core
Assembly
Artemis.Core.dll

A gradient containing a list of ColorGradientStops

public class ColorGradient : IList<ColorGradientStop>, ICollection<ColorGradientStop>, IEnumerable<ColorGradientStop>, IList, ICollection, IEnumerable, INotifyCollectionChanged
Inheritance
object
ColorGradient
Implements

Constructors

ColorGradient()

Creates a new instance of the ColorGradient class

public ColorGradient()

ColorGradient(ColorGradient?)

Creates a new instance of the ColorGradient class

public ColorGradient(ColorGradient? colorGradient)

Parameters

colorGradient ColorGradient

The color gradient to copy

ColorGradient(List<ColorGradientStop>)

Creates a new instance of the ColorGradient class

public ColorGradient(List<ColorGradientStop> stops)

Parameters

stops List<ColorGradientStop>

The stops to copy

Properties

Colors

Gets an array containing the colors of the color gradient.

Note: Making changes to this array will not be reflected on the gradient, is is essentially read-only.
public SKColor[] Colors { get; }

Property Value

SKColor[]

Count

Gets the number of elements contained in the ICollection<T>.

public int Count { get; }

Property Value

int

The number of elements contained in the ICollection<T>.

IsFixedSize

Gets a value indicating whether the IList has a fixed size.

public bool IsFixedSize { get; }

Property Value

bool

true if the IList has a fixed size; otherwise, false.

IsReadOnly

Gets a value indicating whether the ICollection<T> is read-only.

public bool IsReadOnly { get; }

Property Value

bool

true if the ICollection<T> is read-only; otherwise, false.

IsSynchronized

Gets a value indicating whether access to the ICollection is synchronized (thread safe).

public bool IsSynchronized { get; }

Property Value

bool

true if access to the ICollection is synchronized (thread safe); otherwise, false.

this[int]

Gets or sets the element at the specified index.

public ColorGradientStop this[int index] { get; set; }

Parameters

index int

The zero-based index of the element to get or set.

Property Value

ColorGradientStop

The element at the specified index.

Exceptions

ArgumentOutOfRangeException

index is not a valid index in the IList<T>.

NotSupportedException

The property is set and the IList<T> is read-only.

Positions

Gets an array containing the positions of colors of the color gradient.

Note: Making changes to this array will not be reflected on the gradient, is is essentially read-only.
public float[] Positions { get; }

Property Value

float[]

SyncRoot

Gets an object that can be used to synchronize access to the ICollection.

public object SyncRoot { get; }

Property Value

object

An object that can be used to synchronize access to the ICollection.

Methods

Add(ColorGradientStop)

Adds an item to the ICollection<T>.

public void Add(ColorGradientStop item)

Parameters

item ColorGradientStop

The object to add to the ICollection<T>.

Exceptions

NotSupportedException

The ICollection<T> is read-only.

Add(object?)

Adds an item to the IList.

public int Add(object? value)

Parameters

value object

The object to add to the IList.

Returns

int

The position into which the new element was inserted, or -1 to indicate that the item was not inserted into the collection.

Exceptions

NotSupportedException

The IList is read-only.

-or-

The IList has a fixed size.

Clear()

Removes all items from the IList.

public void Clear()

Exceptions

NotSupportedException

The IList is read-only.

Contains(ColorGradientStop)

Determines whether the ICollection<T> contains a specific value.

public bool Contains(ColorGradientStop item)

Parameters

item ColorGradientStop

The object to locate in the ICollection<T>.

Returns

bool

true if item is found in the ICollection<T>; otherwise, false.

Contains(object?)

Determines whether the IList contains a specific value.

public bool Contains(object? value)

Parameters

value object

The object to locate in the IList.

Returns

bool

true if the object is found in the IList; otherwise, false.

CopyTo(ColorGradientStop[], int)

Copies the elements of the ICollection<T> to an Array, starting at a particular Array index.

public void CopyTo(ColorGradientStop[] array, int arrayIndex)

Parameters

array ColorGradientStop[]

The one-dimensional Array that is the destination of the elements copied from ICollection<T>. The Array must have zero-based indexing.

arrayIndex int

The zero-based index in array at which copying begins.

Exceptions

ArgumentNullException

array is null.

ArgumentOutOfRangeException

arrayIndex is less than 0.

ArgumentException

The number of elements in the source ICollection<T> is greater than the available space from arrayIndex to the end of the destination array.

CopyTo(Array, int)

Copies the elements of the ICollection to an Array, starting at a particular Array index.

public void CopyTo(Array array, int index)

Parameters

array Array

The one-dimensional Array that is the destination of the elements copied from ICollection. The Array must have zero-based indexing.

index int

The zero-based index in array at which copying begins.

Exceptions

ArgumentNullException

array is null.

ArgumentOutOfRangeException

index is less than zero.

ArgumentException
   <code class="paramref">array</code> is multidimensional.

-or-

The number of elements in the source ICollection is greater than the available space from index to the end of the destination array.

-or-

The type of the source ICollection cannot be cast automatically to the type of the destination array.

Equals(ColorGradient)

Determines whether all the stops in this gradient are equal to the stops in the given other gradient.

protected bool Equals(ColorGradient other)

Parameters

other ColorGradient

The other gradient to compare to

Returns

bool

Equals(object?)

Determines whether the specified object is equal to the current object.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current object.

Returns

bool

true if the specified object is equal to the current object; otherwise, false.

FlipStops()

Flips the stops of the gradient.

public void FlipStops()

GetColor(float)

Gets a color at any position between 0.0 and 1.0 using interpolation

public SKColor GetColor(float position)

Parameters

position float

A position between 0.0 and 1.0

Returns

SKColor

GetColor(float, int, bool)

Gets a color at any position between 0.0 and 1.0 using interpolation

[Obsolete("Use GetColor(float position) instead.", true)]
public SKColor GetColor(float position, int timesToRepeat = 0, bool seamless = false)

Parameters

position float

A position between 0.0 and 1.0

timesToRepeat int

The amount of times to repeat the positions

seamless bool

A boolean indicating whether to make the gradient seamless by adding the first color behind the last color

Returns

SKColor

GetColorsArray(int, bool)

Gets all the colors in the color gradient

[Obsolete("Use the Colors property instead", true)]
public SKColor[] GetColorsArray(int timesToRepeat = 0, bool seamless = false)

Parameters

timesToRepeat int

The amount of times to repeat the colors

seamless bool

A boolean indicating whether to make the gradient seamless by adding the first color behind the last color

Returns

SKColor[]

An array containing each color in the gradient

GetEnumerator()

Returns an enumerator that iterates through the collection.

public IEnumerator<ColorGradientStop> GetEnumerator()

Returns

IEnumerator<ColorGradientStop>

An enumerator that can be used to iterate through the collection.

GetHashCode()

Serves as the default hash function.

public override int GetHashCode()

Returns

int

A hash code for the current object.

GetPositionsArray(int, bool)

Gets all the positions in the color gradient

[Obsolete("Use the Positions property instead", true)]
public float[] GetPositionsArray(int timesToRepeat = 0, bool seamless = false)

Parameters

timesToRepeat int

The amount of times to repeat the positions

seamless bool

A boolean indicating whether to make the gradient seamless by adding the first color behind the last color

Returns

float[]

An array containing a position for each color between 0.0 and 1.0

GetRandom(int)

Gets a new ColorGradient with random colors from the HSV-spectrum

public static ColorGradient GetRandom(int stops)

Parameters

stops int

The amount of stops to add

Returns

ColorGradient

GetUnicornBarf()

Gets a new ColorGradient with colors looping through the HSV-spectrum

public static ColorGradient GetUnicornBarf()

Returns

ColorGradient

IndexOf(ColorGradientStop)

Determines the index of a specific item in the IList<T>.

public int IndexOf(ColorGradientStop item)

Parameters

item ColorGradientStop

The object to locate in the IList<T>.

Returns

int

The index of item if found in the list; otherwise, -1.

IndexOf(object?)

Determines the index of a specific item in the IList.

public int IndexOf(object? value)

Parameters

value object

The object to locate in the IList.

Returns

int

The index of value if found in the list; otherwise, -1.

Insert(int, ColorGradientStop)

Inserts an item to the IList<T> at the specified index.

public void Insert(int index, ColorGradientStop item)

Parameters

index int

The zero-based index at which item should be inserted.

item ColorGradientStop

The object to insert into the IList<T>.

Exceptions

ArgumentOutOfRangeException

index is not a valid index in the IList<T>.

NotSupportedException

The IList<T> is read-only.

Insert(int, object?)

Inserts an item to the IList at the specified index.

public void Insert(int index, object? value)

Parameters

index int

The zero-based index at which value should be inserted.

value object

The object to insert into the IList.

Exceptions

ArgumentOutOfRangeException

index is not a valid index in the IList.

NotSupportedException

The IList is read-only.

-or-

The IList has a fixed size.

NullReferenceException

value is null reference in the IList.

Interpolate(ColorGradient, float)

Interpolates a color gradient between the this gradient and the provided targetValue.

public ColorGradient Interpolate(ColorGradient targetValue, float progress)

Parameters

targetValue ColorGradient

The second color gradient.

progress float

A value between 0 and 1.

Returns

ColorGradient

The interpolated color gradient.

IsSeamless()

Determines whether the gradient is seamless

public bool IsSeamless()

Returns

bool

true if the gradient is seamless; false otherwise

Randomize(int)

Randomizes the color gradient with the given amount of stops.

public void Randomize(int stops)

Parameters

stops int

The amount of stops to put into the gradient.

Remove(ColorGradientStop)

Removes the first occurrence of a specific object from the ICollection<T>.

public bool Remove(ColorGradientStop item)

Parameters

item ColorGradientStop

The object to remove from the ICollection<T>.

Returns

bool

true if item was successfully removed from the ICollection<T>; otherwise, false. This method also returns false if item is not found in the original ICollection<T>.

Exceptions

NotSupportedException

The ICollection<T> is read-only.

Remove(object?)

Removes the first occurrence of a specific object from the IList.

public void Remove(object? value)

Parameters

value object

The object to remove from the IList.

Exceptions

NotSupportedException

The IList is read-only.

-or-

The IList has a fixed size.

RemoveAt(int)

Removes the IList<T> item at the specified index.

public void RemoveAt(int index)

Parameters

index int

The zero-based index of the item to remove.

Exceptions

ArgumentOutOfRangeException

index is not a valid index in the IList<T>.

NotSupportedException

The IList<T> is read-only.

RotateStops(bool)

Rotates the stops of the gradient shifting every stop over to the position of it's neighbor and wrapping around at the end of the gradient.

public void RotateStops(bool inverse)

Parameters

inverse bool

A boolean indicating whether or not the invert the rotation.

SpreadStops()

Spreads the color stops equally across the gradient.

public void SpreadStops()

ToggleSeamless()

If not already the case, makes the gradient seamless by adding the first color to the end of the gradient and compressing the other stops.

If the gradient is already seamless, removes the last color and spreads the remaining stops to fill the freed space.

public void ToggleSeamless()

Events

CollectionChanged

Occurs when the collection changes.

public event NotifyCollectionChangedEventHandler? CollectionChanged

Event Type

NotifyCollectionChangedEventHandler

StopChanged

Occurs when any of the stops has changed in some way

public event EventHandler? StopChanged

Event Type

EventHandler