Code/Animations/PendulumAnimation.cs
using System;
namespace BetterUI.Animations;
/// <summary>
/// Animates a component rotating around a central point in a pendulum-like motion.
/// </summary>
public class PendulumAnimation : AnimationBase
{
/// <summary>
/// The minimum angle of rotation (in degrees) that the component will reach.
/// </summary>
[Property]
public float MinAngle { get; set; } = -45f;
/// <summary>
/// The maximum angle of rotation (in degrees) that the component will reach.
/// </summary>
[Property]
public float MaxAngle { get; set; } = 45f;
protected override void OnAnimate( float t )
{
var easedTime = ApplyEasing( NormalizedTime, Easing );
var angle = MinAngle + (MaxAngle - MinAngle) * (0.5f + 0.5f * MathF.Sin( easedTime * MathF.PI * 2 ));
WorldRotation = Rotation.FromAxis( Vector3.Up, angle );
}
}