// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
using RGB.NET.Core;
namespace RGB.NET.Brushes.Gradients
{
///
/// Represents a rainbow gradient which circles through all colors of the HUE-color-space.
/// See as reference.
///
public class RainbowGradient : IGradient
{
#region Properties & Fields
///
/// Gets or sets the hue (in degrees) to start from.
///
public double StartHue { get; set; }
///
/// Gets or sets the hue (in degrees) to end the with.
///
public double EndHue { get; set; }
#endregion
#region Constructors
///
/// Initializes a new instance of the class.
///
/// The hue (in degrees) to start from (default: 0)
/// The hue (in degrees) to end with (default: 360)
public RainbowGradient(double startHue = 0, double endHue = 360)
{
this.StartHue = startHue;
this.EndHue = endHue;
}
#endregion
#region Methods
///
/// Gets the color on the rainbow at the given offset.
///
/// The percentage offset to take the color from.
/// The color at the specific offset.
public Color GetColor(double offset)
{
double range = EndHue - StartHue;
double hue = (StartHue + (range * offset)) % 360f;
if (hue < 0)
hue += 360;
return new Color(hue, 1f, 1f);
}
///
public void Move(double offset)
{
// RainbowGradient is calculated inverse
offset *= -1;
StartHue += offset;
EndHue += offset;
if ((StartHue > 360) && (EndHue > 360))
{
StartHue -= 360;
EndHue -= 360;
}
else if ((StartHue < -360) && (EndHue < -360))
{
StartHue += 360;
EndHue += 360;
}
}
#endregion
}
}