//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//
//       LottieGen version:
//           8.1.240821.1+077322fa26
//       
//       Command:
//           LottieGen -Language CSharp -Public -WinUIVersion 3.0 -InputFile Simulation.json
//       
//       Input file:
//           Simulation.json (29001 bytes created 17:52+02:00 Nov 17 2024)
//       
//       LottieGen source:
//           http://aka.ms/Lottie
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
// ____________________________________
// |       Object stats       | Count |
// |__________________________|_______|
// | All CompositionObjects   |    48 |
// |--------------------------+-------|
// | Expression animators     |     1 |
// | KeyFrame animators       |     4 |
// | Reference parameters     |     1 |
// | Expression operations    |     0 |
// |--------------------------+-------|
// | Animated brushes         |     - |
// | Animated gradient stops  |     - |
// | ExpressionAnimations     |     1 |
// | PathKeyFrameAnimations   |     - |
// |--------------------------+-------|
// | ContainerVisuals         |     1 |
// | ShapeVisuals             |     1 |
// |--------------------------+-------|
// | ContainerShapes          |     1 |
// | CompositionSpriteShapes  |     2 |
// |--------------------------+-------|
// | Brushes                  |     2 |
// | Gradient stops           |     2 |
// | CompositionVisualSurface |     - |
// ------------------------------------
using Microsoft.Graphics;
using Microsoft.Graphics.Canvas.Geometry;
using Microsoft.UI.Composition;
using System;
using System.Collections.Generic;
using System.Numerics;
using Windows.UI;

namespace AnimatedVisuals
{
    // Name:        gog-galaxy
    // Frame rate:  24 fps
    // Frame count: 28
    // Duration:    1166.7 mS
    // _____________________________________________________________________________________________
    // |           Marker           |           Constant           | Frame |   mS   |   Progress   |
    // |____________________________|______________________________|_______|________|______________|
    // | NormalToPressed_Start      | M_NormalToPressed_Start      |     0 |    0.0 | 0F           |
    // | NormalToPressed_End        | M_NormalToPressed_End        |     9 |  375.0 | 0.323214293F |
    // | PointerOverToPressed_Start | M_PointerOverToPressed_Start |     9 |  375.0 | 0.323214293F |
    // | PointerOverToPressed_End   | M_PointerOverToPressed_End   |    19 |  791.7 | 0.680357158F |
    // | PressedToNormal_Start      | M_PressedToNormal_Start      |    20 |  833.3 | 0.716071427F |
    // | PressedToNormal_End        | M_PressedToNormal_End        |    28 | 1166.7 | 1F           |
    // | PressedToPointerOver_Start | M_PressedToPointerOver_Start |    28 | 1166.7 | 1F           |
    // | PressedToPointerOver_End   | M_PressedToPointerOver_End   |    28 | 1166.7 | 1F           |
    // ---------------------------------------------------------------------------------------------
    sealed partial class Simulation
        : Microsoft.UI.Xaml.Controls.IAnimatedVisualSource
        , Microsoft.UI.Xaml.Controls.IAnimatedVisualSource2
    {
        // Animation duration: 1.167 seconds.
        internal const long c_durationTicks = 11666666;

        // Marker: NormalToPressed_Start.
        internal const float M_NormalToPressed_Start = 0F;

        // Marker: NormalToPressed_End.
        internal const float M_NormalToPressed_End = 0.323214293F;

        // Marker: PointerOverToPressed_Start.
        internal const float M_PointerOverToPressed_Start = 0.323214293F;

        // Marker: PointerOverToPressed_End.
        internal const float M_PointerOverToPressed_End = 0.680357158F;

        // Marker: PressedToNormal_Start.
        internal const float M_PressedToNormal_Start = 0.716071427F;

        // Marker: PressedToNormal_End.
        internal const float M_PressedToNormal_End = 1F;

        // Marker: PressedToPointerOver_Start.
        internal const float M_PressedToPointerOver_Start = 1F;

        // Marker: PressedToPointerOver_End.
        internal const float M_PressedToPointerOver_End = 1F;

        public Microsoft.UI.Xaml.Controls.IAnimatedVisual TryCreateAnimatedVisual(Compositor compositor)
        {
            object ignored = null;
            return TryCreateAnimatedVisual(compositor, out ignored);
        }

        public Microsoft.UI.Xaml.Controls.IAnimatedVisual TryCreateAnimatedVisual(Compositor compositor, out object diagnostics)
        {
            diagnostics = null;

            var res = 
                new Simulation_AnimatedVisual(
                    compositor
                    );
                res.CreateAnimations();
                return res;
        }

        /// <summary>
        /// Gets the number of frames in the animation.
        /// </summary>
        public double FrameCount => 28d;

        /// <summary>
        /// Gets the frame rate of the animation.
        /// </summary>
        public double Framerate => 24d;

        /// <summary>
        /// Gets the duration of the animation.
        /// </summary>
        public TimeSpan Duration => TimeSpan.FromTicks(11666666);

        /// <summary>
        /// Converts a zero-based frame number to the corresponding progress value denoting the
        /// start of the frame.
        /// </summary>
        public double FrameToProgress(double frameNumber)
        {
            return frameNumber / 28d;
        }

        /// <summary>
        /// Returns a map from marker names to corresponding progress values.
        /// </summary>
        public IReadOnlyDictionary<string, double> Markers =>
            new Dictionary<string, double>
            {
                { "NormalToPressed_Start", 0d },
                { "NormalToPressed_End", 0.323214285714286 },
                { "PointerOverToPressed_Start", 0.323214285714286 },
                { "PointerOverToPressed_End", 0.680357142857143 },
                { "PressedToNormal_Start", 0.716071428571429 },
                { "PressedToNormal_End", 1d },
                { "PressedToPointerOver_Start", 1d },
                { "PressedToPointerOver_End", 1d },
            };

        /// <summary>
        /// Sets the color property with the given name, or does nothing if no such property
        /// exists.
        /// </summary>
        public void SetColorProperty(string propertyName, Color value)
        {
        }

        /// <summary>
        /// Sets the scalar property with the given name, or does nothing if no such property
        /// exists.
        /// </summary>
        public void SetScalarProperty(string propertyName, double value)
        {
        }

        sealed partial class Simulation_AnimatedVisual
            : Microsoft.UI.Xaml.Controls.IAnimatedVisual
            , Microsoft.UI.Xaml.Controls.IAnimatedVisual2
        {
            const long c_durationTicks = 11666666;
            readonly Compositor _c;
            readonly ExpressionAnimation _reusableExpressionAnimation;
            AnimationController _animationController_0;
            CompositionContainerShape _containerShape;
            CompositionPathGeometry _pathGeometry;
            CompositionSpriteShape _spriteShape_0;
            ContainerVisual _root;
            StepEasingFunction _holdThenStepEasingFunction;

            void BindProperty(
                CompositionObject target,
                string animatedPropertyName,
                string expression,
                string referenceParameterName,
                CompositionObject referencedObject)
            {
                _reusableExpressionAnimation.ClearAllParameters();
                _reusableExpressionAnimation.Expression = expression;
                _reusableExpressionAnimation.SetReferenceParameter(referenceParameterName, referencedObject);
                target.StartAnimation(animatedPropertyName, _reusableExpressionAnimation);
            }

            ScalarKeyFrameAnimation CreateScalarKeyFrameAnimation(float initialProgress, float initialValue, CompositionEasingFunction initialEasingFunction)
            {
                var result = _c.CreateScalarKeyFrameAnimation();
                result.Duration = TimeSpan.FromTicks(c_durationTicks);
                result.InsertKeyFrame(initialProgress, initialValue, initialEasingFunction);
                return result;
            }

            Vector2KeyFrameAnimation CreateVector2KeyFrameAnimation(float initialProgress, Vector2 initialValue, CompositionEasingFunction initialEasingFunction)
            {
                var result = _c.CreateVector2KeyFrameAnimation();
                result.Duration = TimeSpan.FromTicks(c_durationTicks);
                result.InsertKeyFrame(initialProgress, initialValue, initialEasingFunction);
                return result;
            }

            AnimationController AnimationController_0()
            {
                if (_animationController_0 != null) { return _animationController_0; }
                var result = _animationController_0 = _c.CreateAnimationController();
                result.Pause();
                BindProperty(_animationController_0, "Progress", "_.Progress", "_", _root);
                return result;
            }

            // - Path 2+Path 1.PathGeometry
            CanvasGeometry Geometry_0()
            {
                var result = CanvasGeometry.CreateGroup(
                    null,
                    new CanvasGeometry[] { Geometry_1(), Geometry_2() },
                    CanvasFilledRegionDetermination.Winding);
                return result;
            }

            // - - Path 2+Path 1.PathGeometry
            CanvasGeometry Geometry_1()
            {
                CanvasGeometry result;
                using (var builder = new CanvasPathBuilder(null))
                {
                    builder.SetFilledRegionDetermination(CanvasFilledRegionDetermination.Winding);
                    builder.BeginFigure(new Vector2(0F, -20F));
                    builder.AddCubicBezier(new Vector2(-11.0459995F, -20F), new Vector2(-20F, -11.0459995F), new Vector2(-20F, 0F));
                    builder.AddCubicBezier(new Vector2(-20F, 11.0459995F), new Vector2(-11.0459995F, 20F), new Vector2(0F, 20F));
                    builder.AddCubicBezier(new Vector2(11.0459995F, 20F), new Vector2(20F, 11.0459995F), new Vector2(20F, 0F));
                    builder.AddCubicBezier(new Vector2(20F, -11.0459995F), new Vector2(11.0459995F, -20F), new Vector2(0F, -20F));
                    builder.EndFigure(CanvasFigureLoop.Closed);
                    result = CanvasGeometry.CreatePath(builder);
                }
                return result;
            }

            // - - Path 2+Path 1.PathGeometry
            CanvasGeometry Geometry_2()
            {
                CanvasGeometry result;
                using (var builder = new CanvasPathBuilder(null))
                {
                    builder.SetFilledRegionDetermination(CanvasFilledRegionDetermination.Winding);
                    builder.BeginFigure(new Vector2(0F, 12F));
                    builder.AddCubicBezier(new Vector2(-6.62699986F, 12F), new Vector2(-12F, 6.62699986F), new Vector2(-12F, 0F));
                    builder.AddCubicBezier(new Vector2(-12F, -6.62699986F), new Vector2(-6.62699986F, -12F), new Vector2(0F, -12F));
                    builder.AddCubicBezier(new Vector2(6.62699986F, -12F), new Vector2(12F, -6.62699986F), new Vector2(12F, 0F));
                    builder.AddCubicBezier(new Vector2(12F, 6.62699986F), new Vector2(6.62699986F, 12F), new Vector2(0F, 12F));
                    builder.EndFigure(CanvasFigureLoop.Closed);
                    result = CanvasGeometry.CreatePath(builder);
                }
                return result;
            }

            // - - Layer aggregator
            // Transforms: back ring
            CompositionColorBrush ColorBrush_AlmostIndigo_FF4E0E99()
            {
                return _c.CreateColorBrush(Color.FromArgb(0xFF, 0x4E, 0x0E, 0x99));
            }

            // - - - Layer aggregator
            // - ShapeGroup: front ring
            // Stop 0
            CompositionColorGradientStop GradientStop_0_AlmostFuchsia_FFCC00EC()
            {
                return _c.CreateColorGradientStop(0F, Color.FromArgb(0xFF, 0xCC, 0x00, 0xEC));
            }

            // - - - Layer aggregator
            // - ShapeGroup: front ring
            // Stop 1
            CompositionColorGradientStop GradientStop_1_AlmostDarkViolet_FF6900D1()
            {
                return _c.CreateColorGradientStop(1F, Color.FromArgb(0xFF, 0x69, 0x00, 0xD1));
            }

            // Layer aggregator
            CompositionContainerShape ContainerShape()
            {
                if (_containerShape != null) { return _containerShape; }
                var result = _containerShape = _c.CreateContainerShape();
                result.Offset = new Vector2(24F, 24F);
                var shapes = result.Shapes;
                // Transforms: back ring
                shapes.Add(SpriteShape_0());
                // ShapeGroup: front ring
                shapes.Add(SpriteShape_1());
                return result;
            }

            // - - Layer aggregator
            // ShapeGroup: front ring
            CompositionLinearGradientBrush LinearGradientBrush()
            {
                var result = _c.CreateLinearGradientBrush();
                var colorStops = result.ColorStops;
                colorStops.Add(GradientStop_0_AlmostFuchsia_FFCC00EC());
                colorStops.Add(GradientStop_1_AlmostDarkViolet_FF6900D1());
                result.MappingMode = CompositionMappingMode.Absolute;
                result.StartPoint = new Vector2(-9F, -15F);
                result.EndPoint = new Vector2(6.19099998F, 12.9569998F);
                return result;
            }

            // Path 2+Path 1.PathGeometry
            CompositionPathGeometry PathGeometry()
            {
                return (_pathGeometry == null)
                    ? _pathGeometry = _c.CreatePathGeometry(new CompositionPath(Geometry_0()))
                    : _pathGeometry;
            }

            // - Layer aggregator
            // Path 2+Path 1
            CompositionSpriteShape SpriteShape_0()
            {
                if (_spriteShape_0 != null) { return _spriteShape_0; }
                var result = _spriteShape_0 = _c.CreateSpriteShape(PathGeometry());
                result.FillBrush = ColorBrush_AlmostIndigo_FF4E0E99();
                return result;
            }

            // - Layer aggregator
            // Path 2+Path 1
            CompositionSpriteShape SpriteShape_1()
            {
                var result = _c.CreateSpriteShape(PathGeometry());
                result.FillBrush = LinearGradientBrush();
                return result;
            }

            // The root of the composition.
            ContainerVisual Root()
            {
                if (_root != null) { return _root; }
                var result = _root = _c.CreateContainerVisual();
                var propertySet = result.Properties;
                propertySet.InsertScalar("Progress", 0F);
                // Layer aggregator
                result.Children.InsertAtTop(ShapeVisual_0());
                return result;
            }

            // - Layer aggregator
            // Rotation
            ScalarKeyFrameAnimation RotationAngleInDegreesScalarAnimation_0_to_360()
            {
                // Frame 0.
                var result = CreateScalarKeyFrameAnimation(0F, 0F, HoldThenStepEasingFunction());
                // Frame 28.
                result.InsertKeyFrame(1F, 360F, _c.CreateCubicBezierEasingFunction(new Vector2(0.166999996F, 0.166999996F), new Vector2(0.833000004F, 0.833000004F)));
                return result;
            }

            // - Layer aggregator
            // Scale
            ScalarKeyFrameAnimation ScaleXScalarAnimation_1_to_1()
            {
                // Frame 0.
                var result = CreateScalarKeyFrameAnimation(0F, 1F, HoldThenStepEasingFunction());
                // Frame 14.
                result.InsertKeyFrame(0.5F, 0.699999988F, _c.CreateCubicBezierEasingFunction(new Vector2(0.289000005F, 0.282000005F), new Vector2(0.662F, 1F)));
                // Frame 28.
                result.InsertKeyFrame(1F, 1F, _c.CreateCubicBezierEasingFunction(new Vector2(0.333000004F, 0F), new Vector2(0.662F, 0.671000004F)));
                return result;
            }

            // - Layer aggregator
            // Scale
            ScalarKeyFrameAnimation ScaleYScalarAnimation_1_to_1()
            {
                // Frame 0.
                var result = CreateScalarKeyFrameAnimation(0F, 1F, HoldThenStepEasingFunction());
                // Frame 14.
                result.InsertKeyFrame(0.5F, 1.13999999F, _c.CreateCubicBezierEasingFunction(new Vector2(0.360000014F, 0.483999997F), new Vector2(0.666999996F, 1F)));
                // Frame 28.
                result.InsertKeyFrame(1F, 1F, _c.CreateCubicBezierEasingFunction(new Vector2(0.333000004F, 0F), new Vector2(0.626999974F, 0.446999997F)));
                return result;
            }

            // Layer aggregator
            ShapeVisual ShapeVisual_0()
            {
                var result = _c.CreateShapeVisual();
                result.Size = new Vector2(48F, 48F);
                result.Shapes.Add(ContainerShape());
                return result;
            }

            StepEasingFunction HoldThenStepEasingFunction()
            {
                if (_holdThenStepEasingFunction != null) { return _holdThenStepEasingFunction; }
                var result = _holdThenStepEasingFunction = _c.CreateStepEasingFunction();
                result.IsFinalStepSingleFrame = true;
                return result;
            }

            // - - Layer aggregator
            // Transforms: back ring
            // Offset
            Vector2KeyFrameAnimation OffsetVector2Animation()
            {
                // Frame 0.
                var result = CreateVector2KeyFrameAnimation(0F, new Vector2(0F, 0F), HoldThenStepEasingFunction());
                // Frame 14.
                result.InsertKeyFrame(0.5F, new Vector2(5.78599977F, 0F), _c.CreateCubicBezierEasingFunction(new Vector2(0.166999996F, 0.166999996F), new Vector2(0.666999996F, 1F)));
                // Frame 28.
                result.InsertKeyFrame(1F, new Vector2(0F, 0F), _c.CreateCubicBezierEasingFunction(new Vector2(0.333000004F, 0F), new Vector2(0.833000004F, 0.833000004F)));
                return result;
            }

            internal Simulation_AnimatedVisual(
                Compositor compositor
                )
            {
                _c = compositor;
                _reusableExpressionAnimation = compositor.CreateExpressionAnimation();
                Root();
            }

            public Visual RootVisual => _root;
            public TimeSpan Duration => TimeSpan.FromTicks(c_durationTicks);
            public Vector2 Size => new Vector2(48F, 48F);
            void IDisposable.Dispose() => _root?.Dispose();

            public void CreateAnimations()
            {
                _containerShape.StartAnimation("RotationAngleInDegrees", RotationAngleInDegreesScalarAnimation_0_to_360(), AnimationController_0());
                _containerShape.StartAnimation("Scale.X", ScaleXScalarAnimation_1_to_1(), AnimationController_0());
                _containerShape.StartAnimation("Scale.Y", ScaleYScalarAnimation_1_to_1(), AnimationController_0());
                _spriteShape_0.StartAnimation("Offset", OffsetVector2Animation(), AnimationController_0());
            }

            public void DestroyAnimations()
            {
                _containerShape.StopAnimation("RotationAngleInDegrees");
                _containerShape.StopAnimation("Scale.X");
                _containerShape.StopAnimation("Scale.Y");
                _spriteShape_0.StopAnimation("Offset");
            }

        }
    }
}
