// ReSharper disable MemberCanBePrivate.Global // ReSharper disable AutoPropertyCanBeMadeGetOnly.Global using System; using RGB.NET.Core; using RGB.NET.Presets.Decorators; namespace RGB.NET.Presets.Textures.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 float _startHue; /// /// Gets or sets the hue (in degrees) to start from. /// public float StartHue { get => _startHue; set => SetProperty(ref _startHue, value); } private float _endHue; /// /// Gets or sets the hue (in degrees) to end the with. /// public float 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(float startHue = 0, float endHue = 360) { this.StartHue = startHue; this.EndHue = endHue; PropertyChanged += (_, _) => 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(float offset) { float range = EndHue - StartHue; float hue = StartHue + (range * offset); return HSVColor.Create(hue, 1, 1); } /// public void Move(float 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, EventArgs.Empty); #endregion } }