Code/Animations/SpiralAnimation.cs
using System;
namespace BetterUI.Animations;
/// <summary>
/// Animates a component in a spiral motion, varying its radius over time.
/// </summary>
public class SpiralAnimation : AnimationBase
{
/// <summary>
/// Gets or sets the initial radius of the spiral.
/// </summary>
[Property]
public float Radius { get; set; } = 5f;
/// <summary>
/// Gets or sets the axis along which the spiral animation occurs.
/// </summary>
[Property, Category( "Animation" )]
public override Vector3 Axis { get; set; } = new(1f, 1f, 0f);
/// <summary>
/// Animates the component in a spiral pattern based on the current time.
/// </summary>
/// <param name="t">The normalized time of the animation.</param>
protected override void OnAnimate( float t )
{
var easedTime = ApplyEasing( NormalizedTime, Easing );
var angle = easedTime * MathF.PI * 2;
var currentRadius = Radius + 1f * easedTime;
var x = Axis.x != 0 ? StartPosition.x + currentRadius * MathF.Cos( angle ) : StartPosition.x;
var y = Axis.y != 0 ? StartPosition.y + currentRadius * MathF.Sin( angle ) : StartPosition.y;
var z = Axis.z != 0 ? StartPosition.z + currentRadius * MathF.Sin( angle ) : StartPosition.z;
WorldPosition = new Vector3( x, y, z );
}
}