// ReSharper disable MemberCanBePrivate.Global // ReSharper disable AutoPropertyCanBeMadeGetOnly.Global using System; 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 : AbstractDecoratable, IGradient { #region Properties & Fields private double _startHue; /// /// Gets or sets the hue (in degrees) to start from. /// public double StartHue { get => _startHue; set => SetProperty(ref _startHue, value); } private double _endHue; /// /// Gets or sets the hue (in degrees) to end the with. /// public double EndHue { get => _endHue; set => SetProperty(ref _endHue, value); } #endregion #region Events /// public event EventHandler GradientChanged; #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; PropertyChanged += (sender, args) => OnGradientChanged(); } #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); return HSVColor.Create(hue, 1, 1); } /// public void Move(double offset) { // RainbowGradient is calculated inverse offset *= -1; StartHue += offset; EndHue += offset; while ((StartHue > 360) && (EndHue > 360)) { StartHue -= 360; EndHue -= 360; } while ((StartHue < -360) && (EndHue < -360)) { StartHue += 360; EndHue += 360; } } /// /// Should be called to indicate that the gradient was changed. /// protected void OnGradientChanged() => GradientChanged?.Invoke(this, null); #endregion } }