public override async Task <CompositionDrawingSurface> LoadResources()
        {
            var graphicsEffect = new ArithmeticCompositeEffect
            {
                Name          = "Arithmetic",
                Source1       = new CompositionEffectSourceParameter("ImageSource"),
                Source1Amount = .25f,
                Source2       = new Transform2DEffect
                {
                    Name   = "LightMapTransform",
                    Source = new CompositionEffectSourceParameter("LightMap")
                },
                Source2Amount  = 0,
                MultiplyAmount = 1
            };

            _effectFactory = _compositor.CreateEffectFactory(graphicsEffect, new[] { "LightMapTransform.TransformMatrix" });

            // Create the image
            _lightMap = await ImageLoader.Instance.LoadFromUriAsync(new Uri("ms-appx:///Assets/NormalMapsAndMasks/conemap.jpg"));

            // Create the animations
            float sweep      = (float)Math.PI / 10f;
            float fullCircle = (float)Math.PI * -2f;

            _enterAnimation = _compositor.CreateScalarKeyFrameAnimation();
            _enterAnimation.InsertKeyFrame(0.1f, fullCircle);
            _enterAnimation.InsertKeyFrame(0.4f, fullCircle + sweep);
            _enterAnimation.InsertKeyFrame(0.8f, fullCircle - sweep);
            _enterAnimation.InsertKeyFrame(1.0f, fullCircle);
            _enterAnimation.Duration          = TimeSpan.FromMilliseconds(4500);
            _enterAnimation.IterationBehavior = AnimationIterationBehavior.Count;
            _enterAnimation.IterationCount    = 1;

            _exitAnimation = _compositor.CreateScalarKeyFrameAnimation();
            _exitAnimation.InsertKeyFrame(1.0f, 0f);
            _exitAnimation.Duration          = TimeSpan.FromMilliseconds(1000);
            _exitAnimation.IterationBehavior = AnimationIterationBehavior.Count;
            _exitAnimation.IterationCount    = 1;

            var propsNode = ExpressionValues.Reference.CreatePropertySetReference("props");
            var propsCenterPointOffset = propsNode.GetVector2Property("CenterPointOffset");
            var propsRotation          = propsNode.GetScalarProperty("Rotation");
            var propsScale             = propsNode.GetScalarProperty("Scale");

            _transformExpressionNode = EF.CreateTranslation(-propsCenterPointOffset) *
                                       EF.Matrix3x2(EF.Cos(propsRotation) * propsScale,
                                                    EF.Sin(propsRotation),
                                                    -EF.Sin(propsRotation),
                                                    EF.Cos(propsRotation) * propsScale,
                                                    0,
                                                    0) *
                                       EF.CreateTranslation(propsCenterPointOffset + propsNode.GetVector2Property("Translate"));

            return(null);
        }
        private void SamplePage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            Compositor      compositor = ElementCompositionPreview.GetElementVisual(MyGrid).Compositor;
            ContainerVisual container  = compositor.CreateContainerVisual();

            ElementCompositionPreview.SetElementChildVisual(MyGrid, container);


            //
            // Create a couple of SurfaceBrushes for the orbiters and center
            //

            _redBallSurface  = ImageLoader.Instance.LoadFromUri(new Uri("ms-appx:///Samples/SDK 10586/PropertySets/RedBall.png"));
            _blueBallSurface = ImageLoader.Instance.LoadFromUri(new Uri("ms-appx:///Samples/SDK 10586/PropertySets/BlueBall.png"));


            //
            // Create the center and orbiting sprites
            //

            SpriteVisual redSprite = compositor.CreateSpriteVisual();

            redSprite.Brush  = _redBallSurface.Brush;
            redSprite.Size   = new Vector2(100f, 100f);
            redSprite.Offset = new Vector3((float)Window.Current.Bounds.Width / 2 - redSprite.Size.X / 2, 150f, 0f);
            container.Children.InsertAtTop(redSprite);

            SpriteVisual blueSprite = compositor.CreateSpriteVisual();

            blueSprite.Brush  = _blueBallSurface.Brush;
            blueSprite.Size   = new Vector2(25f, 25f);
            blueSprite.Offset = new Vector3((float)Window.Current.Bounds.Width / 2 - redSprite.Size.X / 2, 50f, 0f);
            container.Children.InsertAtTop(blueSprite);

            //
            // Create the PropertySet that contains all the value referenced in the expression. We can also
            // animate these properties, leading to the expression being re-evaluated per frame.
            //

            _propertySet = compositor.CreatePropertySet();
            _propertySet.InsertScalar("Rotation", 0f);
            _propertySet.InsertVector3("CenterPointOffset", new Vector3(redSprite.Size.X / 2 - blueSprite.Size.X / 2,
                                                                        redSprite.Size.Y / 2 - blueSprite.Size.Y / 2,
                                                                        0));

            //
            // Create the expression.  This expression positions the orbiting sprite relative to the center of
            // of the red sprite's center.  As we animate the red sprite's position, the expression will read
            // the current value of it's offset and keep the blue sprite locked in orbit.
            //

            var propSetCenterPoint = _propertySet.GetReference().GetVector3Property("CenterPointOffset");
            var propSetRotation    = _propertySet.GetReference().GetScalarProperty("Rotation");
            var orbitExpression    = redSprite.GetReference().Offset + propSetCenterPoint +
                                     EF.Vector3(
                EF.Cos(EF.ToRadians(propSetRotation)) * 150,
                EF.Sin(EF.ToRadians(propSetRotation)) * 75,
                0);

            // Start the expression animation!
            blueSprite.StartAnimation("Offset", orbitExpression);

            // Now animate the rotation property in the property bag, this generates the orbitting motion.
            var linear       = compositor.CreateLinearEasingFunction();
            var rotAnimation = compositor.CreateScalarKeyFrameAnimation();

            rotAnimation.InsertKeyFrame(1.0f, 360f, linear);
            rotAnimation.Duration          = TimeSpan.FromMilliseconds(4000);
            rotAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
            _propertySet.StartAnimation("Rotation", rotAnimation);

            // Lastly, animation the Offset of the red sprite to see the expression track appropriately
            var offsetAnimation = compositor.CreateScalarKeyFrameAnimation();

            offsetAnimation.InsertKeyFrame(0f, 50f);
            offsetAnimation.InsertKeyFrame(.5f, 150f);
            offsetAnimation.InsertKeyFrame(1f, 50f);
            offsetAnimation.Duration          = TimeSpan.FromMilliseconds(4000);
            offsetAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
            redSprite.StartAnimation("Offset.Y", offsetAnimation);
        }