HueInterpolator.cs 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. // Copyright (c) Craftwork Games. All rights reserved.
  2. // Licensed under the MIT license.
  3. // See LICENSE file in the project root for full license information.
  4. using MonoGame.Extended.Particles.Data;
  5. namespace MonoGame.Extended.Particles.Modifiers.Interpolators;
  6. /// <summary>
  7. /// An interpolator that gradually changes only the hue component of particle colors over their lifetime.
  8. /// </summary>
  9. /// <remarks>
  10. /// Unlike <see cref="ColorInterpolator"/> which changes all HSL components, this interpolator
  11. /// affects only the hue component, preserving the particle's existing saturation and lightness values.
  12. /// This allows for color cycling effects while maintaining consistent saturation and brightness.
  13. /// </remarks>
  14. public class HueInterpolator : Interpolator<float>
  15. {
  16. /// <summary>
  17. /// Updates a particle's hue by interpolating between the start and end values.
  18. /// </summary>
  19. /// <param name="amount">The normalized interpolation amount (from 0.0 to 1.0).</param>
  20. /// <param name="particle">A pointer to the particle to update.</param>
  21. public override unsafe void Update(float amount, Particle* particle)
  22. {
  23. if (!Enabled) { return; }
  24. float h = StartValue + (EndValue - StartValue) * amount;
  25. particle->Color[0] = h;
  26. }
  27. }