Skip to content
This repository was archived by the owner on Aug 6, 2021. It is now read-only.

Implementing an own gradient

DarthAffe edited this page Nov 15, 2015 · 3 revisions

Implementing an own gradient is quite easy.
All you need to do is implementing the IGradient-interface which looks like this:

public interface IGradient
{
    Color GetColor(float offset);
}

Just place your calculation-logic inside the GetColor-Method and return the Color for the requested offset. (The offset represents the percentage value of "progress" on the gradient.)
Even if it might not be needed please handle the case of a negative offset or values greater 1!

Before you start take a look at the helper-methods in the ColorHelper- and GradientHelper-classes. They might be useful!

If you want to work with GradientStops (like the LinearGradient) you can derive from the AbstractGradient-class which implements some logic helping with that.

If you need a reference on how the implementation might look, you can take the LinearGradient or the RainbowGradient.