예제 #1
0
        public BorderPlayground()
        {
            _compositor  = ElementCompositionPreview.GetElementVisual(this).Compositor;
            _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor);

            this.InitializeComponent();
        }
예제 #2
0
        private void InitializeCompositionVariables()
        {
            var bounds          = ApplicationView.GetForCurrentView().VisibleBounds;
            var maxWindowWidth  = bounds.Width.ToFloat();
            var maxWindowHeight = bounds.Height.ToFloat();
            var maxWindowRadius = Math.Max(maxWindowWidth, maxWindowHeight);

            // Setup sky visual's size, position, opacity, etc.
            _skyVisual             = Sky.ContainerVisual();
            _skyVisual.Size        = new Vector2(maxWindowRadius * SkyVisualAreaRatio);
            _skyVisual.Offset      = new Vector3(-SkyVisualRadius + maxWindowWidth / 2.0f, -SkyVisualRadius + maxWindowHeight / 2.0f, 0.0f);
            _skyVisual.CenterPoint = new Vector3(SkyVisualRadius, SkyVisualRadius, 0.0f);
            _skyVisual.Opacity     = 0;

            _compositor = _skyVisual.Compositor;
            _reading    = _compositor.CreatePropertySet();
            _reading.InsertVector3("Offset", new Vector3(0.0f, 0.0f, 0.0f));
            _imageLoader         = ImageLoaderFactory.CreateImageLoader(_compositor);
            _circleBrush         = _compositor.CreateSurfaceBrush();
            _circleBrush.Surface = _imageLoader.LoadImageFromUri(new Uri(StarUriString));

            if (_inclinometer != null)
            {
                SetupSkyVisualOffsetExpressionAnimation();
            }
        }
예제 #3
0
        private void SamplePage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            // Get backing visual from shadow container and interop compositor
            _shadowContainer = ElementCompositionPreview.GetElementVisual(ShadowContainer);
            _compositor      = _shadowContainer.Compositor;

            // Get CompositionImage, its sprite visual
            _image       = VisualTreeHelperExtensions.GetFirstDescendantOfType <CompositionImage>(ShadowContainer);
            _imageVisual = _image.SpriteVisual;

            // Load mask asset onto surface using helpers in SamplesCommon
            _imageLoader      = ImageLoaderFactory.CreateImageLoader(_compositor);
            _imageMaskSurface = _imageLoader.CreateCircleSurface(200, Colors.White);

            // Create surface brush for mask
            CompositionSurfaceBrush mask = _compositor.CreateSurfaceBrush();

            mask.Surface = _imageMaskSurface.Surface;

            // Get surface brush from composition image
            CompositionSurfaceBrush source = _image.SurfaceBrush as CompositionSurfaceBrush;

            // Create mask brush for toggle mask functionality
            _maskBrush        = _compositor.CreateMaskBrush();
            _maskBrush.Mask   = mask;
            _maskBrush.Source = source;

            // Initialize toggle mask
            _isMaskEnabled = false;
        }
예제 #4
0
        private void Setup()
        {
            if (!_firstRun)
            {
                return;
            }
            _firstRun = false;

            var shadowContainer = ElementCompositionPreview.GetElementVisual(ImageContainer);
            var compositor      = shadowContainer.Compositor;

            var image       = ImageContainer.FindChildren <CompositionImage>().First();
            var imageVisual = image.SpriteVisual;

            var imageLoader      = ImageLoaderFactory.CreateImageLoader(compositor);
            var imageMaskSurface = imageLoader.CreateManagedSurfaceFromUri(new Uri("ms-appx:///Helpers/Composition/CircleMask.png"));

            var mask = compositor.CreateSurfaceBrush();

            mask.Surface = imageMaskSurface.Surface;

            var source = image.SurfaceBrush as CompositionSurfaceBrush;

            var maskBrush = compositor.CreateMaskBrush();

            maskBrush.Mask   = mask;
            maskBrush.Source = source;

            image.Brush = maskBrush;
            Shadow.Mask = maskBrush.Mask;

            this.Fade(value: 1, delay: 1000).StartAsync();
        }
        private CompositionSurfaceBrush CreateBrushFromAsset(string name, out Size size)
        {
            IImageLoader imageLoader          = ImageLoaderFactory.CreateImageLoader(m_compositor);
            CompositionDrawingSurface surface = imageLoader.LoadImageFromUri(new Uri("ms-appx:///Assets/" + name));

            size = surface.Size;
            return(m_compositor.CreateSurfaceBrush(surface));
        }
        /// <summary>
        /// Initialize Composition
        /// </summary>
        private void InitializeComposition()
        {
            // Retrieve an instance of the Compositor from the backing Visual of the Page
            _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;

            // Create a root visual from the Compositor
            _root = _compositor.CreateContainerVisual();

            // Set the root ContainerVisual as the XAML Page Visual
            ElementCompositionPreview.SetElementChildVisual(this, _root);

            // Assign initial values to variables used to store updated offsets for the visuals
            float posXUpdated = _posX;
            float posYUpdated = _posY;

            // Create a list of image brushes that can be applied to a visual
            string[] imageNames =
            {
                "01.png",
                "02.png",
                "03.png",
                "04.png",
                "05.png",
                "06.png",
                "07.png",
                "08.png",
                "60Banana.png",
                "60Lemon.png",
                "60Vanilla.png",
                "60Mint.png",
                "60Orange.png",
                "110Strawberry.png",
                "60SprinklesRainbow.png"
            };
            List <CompositionSurfaceBrush> imageBrushList = new List <CompositionSurfaceBrush>();
            IImageLoader imageFactory = ImageLoaderFactory.CreateImageLoader(_compositor);

            for (int k = 0; k < imageNames.Length; k++)
            {
                var surface = imageFactory.LoadImageFromUri(new Uri("ms-appx:///Assets/Images/Composition/ImplicitAnimation/" + imageNames[k]));
                imageBrushList.Add(_compositor.CreateSurfaceBrush(surface));
            }

            // Create nxn matrix of visuals where n=row/ColumnCount-1 and passes random image brush to the function
            // that creates a visual
            for (int i = 1; i < _rowCount; i++)
            {
                posXUpdated = i * _distance;
                for (int j = 1; j < _columnCount; j++)
                {
                    CompositionSurfaceBrush brush = imageBrushList[randomBrush.Next(imageBrushList.Count)];

                    posYUpdated = j * _distance;
                    _root.Children.InsertAtTop(CreateChildElement(brush, posXUpdated, posYUpdated));
                }
            }
            EnableAnimationOnChildren(EnableAnimations.IsChecked.GetValueOrDefault());
        }
예제 #7
0
 /// <summary>
 /// Creates the circle used in the circle brush if not already created.
 /// </summary>
 private void EnsureCircleBrush()
 {
     if (_circleBrush == null)
     {
         _imageLoader   = ImageLoaderFactory.CreateImageLoader(_compositor);
         _circleSurface = _imageLoader.CreateCircleSurface(200, Colors.White);
         _circleBrush   = _compositor.CreateSurfaceBrush(_circleSurface.Surface);
     }
 }
 /// <summary>
 /// Creates the circle used in the circle brush if not already created.
 /// </summary>
 private void EnsureCircleBrush()
 {
     if (_circleBrush == null)
     {
         _imageLoader   = ImageLoaderFactory.CreateImageLoader(_compositor);
         _circleSurface = _imageLoader.CreateManagedSurfaceFromUri(new Uri(CircleImagePath));
         _circleBrush   = _compositor.CreateSurfaceBrush(_circleSurface.Surface);
     }
 }
예제 #9
0
        public CompCapabilities()
        {
            this.InitializeComponent();

            _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;

            _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor);

            // Get hardware capabilities and register changed event listener
            _capabilities = CompositionCapabilities.GetForCurrentView();
        }
예제 #10
0
        public ColorBloomTransitionHelper(UIElement hostForVisual)
        {
            this.hostForVisual = hostForVisual;

            var visual = ElementCompositionPreview.GetElementVisual(hostForVisual);

            _compositor = visual.Compositor;


            _containerForVisuals = _compositor.CreateContainerVisual();
            ElementCompositionPreview.SetElementChildVisual(hostForVisual, _containerForVisuals);

            _imageLoader       = ImageLoaderFactory.CreateImageLoader(_compositor);
            _circleMaskSurface = _imageLoader.CreateCircleSurface(200, Colors.White);
        }
        async private Task LoadImages()
        {
            _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor);

            string[] imageNames = { "Photos/Pic06",           "Photos/Pic30",           "Photos/Pic39",            "Landscapes/Landscape-7",
                                    "Landscapes/Landscape-8", "Landscapes/Landscape-9", "Landscapes/Landscape-12", "Photos/pic22",
                                    "Photos/Pic11" };

            for (int i = 0; i < imageNames.Length; ++i)
            {
                var uri     = new Uri($"ms-appx:///Assets/{imageNames[i]}.jpg");
                var surface = await SurfaceLoader.LoadFromUri(uri);

                _imageSurfaces[i] = _compositor.CreateSurfaceBrush(surface);
            }
        }
        public NineGridResizing()
        {
            this.InitializeComponent();

            _compositor  = ElementCompositionPreview.GetElementVisual(this).Compositor;
            _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor);

            // Add page loaded event listener
            this.Loaded += NineGridResizing_Loaded;

            // Set data context for data binding
            DataContext = this;

            // Sprite visual to be painted
            _ninegridVisual = _compositor.CreateSpriteVisual();

            // Create ninegridbrush and paint on visual;
            _ninegridBrush        = _compositor.CreateNineGridBrush();
            _ninegridVisual.Brush = _ninegridBrush;

            // Clip compgrid
            var compGrid = ElementCompositionPreview.GetElementVisual(CompGrid);

            compGrid.Clip = _compositor.CreateInsetClip();

            // Scene container to be scaled
            _backgroundContainer = ElementCompositionPreview.GetElementVisual(bkgHost);

            // Insert Composition island
            ElementCompositionPreview.SetElementChildVisual(ngHost, _ninegridVisual);

            // Instatiate brush scenario list and fill with created brush scenarios
            _nineGridBrushScenarios = new ObservableCollection <INineGridScenario>(CreateBrushes(_compositor, _imageLoader, _ninegridVisual.Size));

            // Set default combo box selection to first item
            BrushScenarioSelected = _nineGridBrushScenarios.FirstOrDefault();

            // Value timer initialization for sliders
            _valueTimerXSlider = new ValueTimer <float>();
            _valueTimerXSlider.ValueChanged += OnXSliderValueChanged;

            _valueTimerYSlider = new ValueTimer <float>();
            _valueTimerYSlider.ValueChanged += OnYSliderValueChanged;

            _valueTimerScaleSlider = new ValueTimer <float>();
            _valueTimerScaleSlider.ValueChanged += OnScaleSliderValueChanged;
        }
예제 #13
0
        /// <summary>
        /// Creates an instance of the ColorBloomTransitionHelper.
        /// Any visuals to be later created and animated will be hosted within the specified UIElement.
        /// </summary>
        public ColorBloomTransitionHelper(UIElement hostForVisual)
        {
            this.hostForVisual = hostForVisual;

            // we have an element in the XAML tree that will host our Visuals
            var visual = ElementCompositionPreview.GetElementVisual(hostForVisual);

            _compositor = visual.Compositor;

            // create a container
            // adding children to this container adds them to the live visual tree
            _containerForVisuals = _compositor.CreateContainerVisual();
            ElementCompositionPreview.SetElementChildVisual(hostForVisual, _containerForVisuals);

            // initialize the ImageLoader and create the circle mask
            _imageLoader       = ImageLoaderFactory.CreateImageLoader(_compositor);
            _circleMaskSurface = _imageLoader.CreateManagedSurfaceFromUri(new Uri("ms-appx:///Samples/SDK 10586/TransitionAnimation-ColorBloom/CircleOpacityMask.png"));
        }
        /// <summary>
        /// Creates an instance of the ColorBloomTransitionHelper.
        /// Any visuals to be later created and animated will be hosted within the specified UIElement.
        /// </summary>
        public ColorBloomTransitionHelper(UIElement hostForVisual)
        {
            this.hostForVisual = hostForVisual;

            // we have an element in the XAML tree that will host our Visuals
            var visual = ElementCompositionPreview.GetElementVisual(hostForVisual);

            _compositor = visual.Compositor;

            // create a container
            // adding children to this container adds them to the live visual tree
            _containerForVisuals = _compositor.CreateContainerVisual();
            ElementCompositionPreview.SetElementChildVisual(hostForVisual, _containerForVisuals);

            // initialize the ImageLoader and create the circle mask
            _imageLoader       = ImageLoaderFactory.CreateImageLoader(_compositor);
            _circleMaskSurface = _imageLoader.CreateCircleSurface(200, Colors.White);
        }
        private void SamplePage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            // Get backing visual from shadow container and interop compositor
            _shadowContainer = ElementCompositionPreview.GetElementVisual(ShadowContainer);
            _compositor      = _shadowContainer.Compositor;

            // Get CompositionImage, its sprite visual
            _image       = VisualTreeHelperExtensions.GetFirstDescendantOfType <CompositionImage>(ShadowContainer);
            _imageVisual = _image.SpriteVisual;

            // Add drop shadow to image visual
            _shadow             = _compositor.CreateDropShadow();
            _imageVisual.Shadow = _shadow;

            // Initialize sliders to shadow defaults - with the exception of offset
            BlurRadiusSlider.Value = _shadow.BlurRadius;    //defaults to 9.0f
            OffsetXSlider.Value    = _shadow.Offset.X;      //defaults to 0
            OffsetYSlider.Value    = _shadow.Offset.Y;      //defaults to 0
            RedSlider.Value        = _shadow.Color.R;       //defaults to 0 (black.R)
            GreenSlider.Value      = _shadow.Color.G;       //defaults to 0 (black.G)
            BlueSlider.Value       = _shadow.Color.B;       //defaults to 0 (black.B)

            // Load mask asset onto surface using helpers in SamplesCommon
            _imageLoader      = ImageLoaderFactory.CreateImageLoader(_compositor);
            _imageMaskSurface = _imageLoader.CreateManagedSurfaceFromUri(new Uri("ms-appx:///Assets/CircleMask.png"));

            // Create surface brush for mask
            CompositionSurfaceBrush mask = _compositor.CreateSurfaceBrush();

            mask.Surface = _imageMaskSurface.Surface;

            // Get surface brush from composition image
            CompositionSurfaceBrush source = _image.SurfaceBrush as CompositionSurfaceBrush;

            // Create mask brush for toggle mask functionality
            _maskBrush        = _compositor.CreateMaskBrush();
            _maskBrush.Mask   = mask;
            _maskBrush.Source = source;

            // Initialize toggle mask and animation to false
            _isMaskEnabled      = false;
            _isAnimationEnabled = false;
        }
        /// <summary>
        /// MainPage_Loaded is used for all of our initialization to keep the UI thread mostly free.
        /// </summary>
        /// <param name="sender">not used</param>
        /// <param name="e">not used</param>
        private async void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            _compositor  = ElementCompositionPreview.GetElementVisual(sender as UIElement).Compositor;
            _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor);
            var scrollProperties = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(Scroller);

            var uri = new Uri("ms-appx:///Samples/SDK 10586/Z-Order Scrolling/RollingWaves.jpg");

            ParallaxingImage.Source = uri;
            ParallaxingImage.Brush  = await InitializeCrossFadeEffect(uri);

            var maskedBrush = InitializeCompositeEffect();

            ParallaxingImage.SizeChanged += (s, ev) => { UpdateSizes(); };

            InitializeBackgroundImageVisual(scrollProperties);
            InitializeFrontVisual(scrollProperties, maskedBrush);
            InitializeBehindVisual(scrollProperties, maskedBrush);

            UpdateSizes();
        }
예제 #17
0
        private void SetupCompositionImage(CompositionImage image, News.Helpers.Composition.CompositionShadow shadow)
        {
            var imageVisual = image.SpriteVisual;
            var compositor  = imageVisual.Compositor;

            var imageLoader      = ImageLoaderFactory.CreateImageLoader(compositor);
            var imageMaskSurface = imageLoader.CreateManagedSurfaceFromUri(new Uri("ms-appx:///Helpers/Composition/CircleMask.png"));

            var mask = compositor.CreateSurfaceBrush();

            mask.Surface = imageMaskSurface.Surface;

            var source = image.SurfaceBrush as CompositionSurfaceBrush;

            var maskBrush = compositor.CreateMaskBrush();

            maskBrush.Mask   = mask;
            maskBrush.Source = source;

            image.Brush = maskBrush;
            shadow.Mask = maskBrush.Mask;
        }
예제 #18
0
        private async void InitComposition()
        {
            // Obtain a Compositor and use it to initialize our ImageLoader.
            // Make sure you have the CompositionImageLoader nuget package:
            // https://www.nuget.org/packages/Robmikh.Util.CompositionImageLoader
            var compositor  = ElementCompositionPreview.GetElementVisual(this).Compositor;
            var imageLoader = ImageLoaderFactory.CreateImageLoader(compositor);

            // Create a ManagedSurface, which is resilient to having our device lost suddenly.
            var managedSurface = await imageLoader.CreateManagedSurfaceFromUriAsync(new Uri("ms-appx:///Assets/tripphoto1.jpg"));

            // Create a brush using our new surface.
            var brush = compositor.CreateSurfaceBrush(managedSurface.Surface);

            // Create a visual and assign our brush to the visual's Brush property.
            var visual = compositor.CreateSpriteVisual();

            visual.Size   = managedSurface.Size.ToVector2(); // We use the image's real size so we avoid stretching. This isn't strictly necessary.
            visual.Offset = new Vector3(50, 50, 0);
            visual.Brush  = brush;

            // Attach our visual into the tree.
            ElementCompositionPreview.SetElementChildVisual(this, visual);
        }
예제 #19
0
        private async void InitComposition()
        {
            // Store our Compositor and create our ImageLoader.
            _compositor  = ElementCompositionPreview.GetElementVisual(this).Compositor;
            _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor);

            // Setup our effect definition. First is the CompositeEffect that will take
            // our sources and produce the intersection of the images (because we selected
            // the DestinationIn mode for the effect). Next we take our CompositeEffect
            // and make it the source of our next effect, the InvertEffect. This will take
            // the intersection image and invert the colors. Finally we take that combined
            // effect and put it through a HueRotationEffect, were we can adjust the colors
            // using the Angle property (which we will animate below).
            IGraphicsEffect graphicsEffect = new HueRotationEffect
            {
                Name   = "hueEffect",
                Angle  = 0.0f,
                Source = new InvertEffect
                {
                    Source = new CompositeEffect
                    {
                        Mode    = Microsoft.Graphics.Canvas.CanvasComposite.DestinationIn,
                        Sources =
                        {
                            new CompositionEffectSourceParameter("image"),
                            new CompositionEffectSourceParameter("mask")
                        }
                    }
                }
            };

            // Create our effect factory using the effect definition and mark the Angle
            // property as adjustable/animatable.
            _effectFactory = _compositor.CreateEffectFactory(graphicsEffect, new string[] { "hueEffect.Angle" });

            // Create MangedSurfaces for both our base image and the mask we'll be using.
            // The mask is a transparent image with a white circle in the middle. This is
            // important since the CompositeEffect will use just the circle for the
            // intersectionsince the rest is transparent.
            var managedImageSurface = await _imageLoader.CreateManagedSurfaceFromUriAsync(new Uri("ms-appx:///Assets/tripphoto1.jpg"));

            var managedMaskSurface = await _imageLoader.CreateManagedSurfaceFromUriAsync(new Uri("ms-appx:///Assets/CircleMask.png"));

            // Create brushes from our surfaces.
            var imageBrush = _compositor.CreateSurfaceBrush(managedImageSurface.Surface);
            var maskBrush  = _compositor.CreateSurfaceBrush(managedMaskSurface.Surface);

            // Create an setup our effect brush.Assign both the base image and mask image
            // brushes as source parameters in the effect (with the same names we used in
            // the effect definition). If we wanted, we could create many effect brushes
            // and use different images in all of them.
            var effectBrush = _effectFactory.CreateBrush();

            effectBrush.SetSourceParameter("image", imageBrush);
            effectBrush.SetSourceParameter("mask", maskBrush);

            // All that's left is to create a visual, assign the effect brush to the Brush
            // property, and attach it into the tree...
            var visual = _compositor.CreateSpriteVisual();

            visual.Size   = managedImageSurface.Size.ToVector2();
            visual.Offset = new Vector3(50, 50, 0);

            visual.Brush = effectBrush;

            ElementCompositionPreview.SetElementChildVisual(this, visual);

            // ... but wait! There's more! We're going to animate the Angle property
            // to get a really trippy color effect on our masked inverted image.
            AnimateEffect(effectBrush);
        }
예제 #20
0
        async private void LoadImages()
        {
            int loadedImageCount = 0;

            // Create the loader
            _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor);


            //
            // Populate/load our unique list of image textures.
            //

            for (int i = 0; i < (int)NamedImage.Count; i++)
            {
                var name = (NamedImage)i;

                Uri uri = new Uri($"ms-appx:///Assets/Photos/{name.ToString()}.jpg");
                _managedSurfaces[i] = _imageLoader.CreateManagedSurfaceFromUri(uri);

                var surface = await _imageLoader.LoadImageFromUriAsync(uri);

                _imageBrushes[i] = _compositor.CreateSurfaceBrush(surface);

                loadedImageCount++;
            }


            //
            // Populate/load our unique list of "text" image textures.
            //

            _textBrushes = new CompositionSurfaceBrush[_textNodes.Length];

            for (int i = 0; i < _textNodes.Length; i++)
            {
                var textNode = _textNodes[i];

                var textSurface = SurfaceLoader.LoadText(textNode.Text, new Size(textNode.TextureSize.X, textNode.TextureSize.Y), textNode.TextFormat, Colors.Black, Colors.Transparent);

                _textBrushes[i] = _compositor.CreateSurfaceBrush(textSurface);

                //
                // Remember the index of the brush so that we can refer to it later.
                //

                textNode.BrushIndex = i;

                loadedImageCount++;
            }



            //
            // Once we've loaded all of the images, we can continue populating the world.
            //

            if (loadedImageCount == _imageBrushes.Length + _textBrushes.Length)
            {
                PopulateWorld();
            }
        }
예제 #21
0
        private void SamplePage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            Compositor compositor = ElementCompositionPreview.GetElementVisual(MyGrid).Compositor;

            _imageLoader = ImageLoaderFactory.CreateImageLoader(compositor);
            ContainerVisual container = compositor.CreateContainerVisual();

            ElementCompositionPreview.SetElementChildVisual(MyGrid, container);


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

            CompositionSurfaceBrush redBrush = compositor.CreateSurfaceBrush();

            _redBallSurface  = _imageLoader.CreateManagedSurfaceFromUri(new Uri("ms-appx:///Samples/SDK 10586/PropertySets/RedBall.png"));
            redBrush.Surface = _redBallSurface.Surface;

            CompositionSurfaceBrush blueBrush = compositor.CreateSurfaceBrush();

            _blueBallSurface  = _imageLoader.CreateManagedSurfaceFromUri(new Uri("ms-appx:///Samples/SDK 10586/PropertySets/BlueBall.png"));
            blueBrush.Surface = _blueBallSurface.Surface;


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

            SpriteVisual redSprite = compositor.CreateSpriteVisual();

            redSprite.Brush  = redBrush;
            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  = blueBrush;
            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 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.
            //

            ExpressionAnimation expressionAnimation = compositor.CreateExpressionAnimation("visual.Offset + " +
                                                                                           "propertySet.CenterPointOffset + " +
                                                                                           "Vector3(cos(ToRadians(propertySet.Rotation)) * 150," +
                                                                                           "sin(ToRadians(propertySet.Rotation)) * 75, 0)");

            //
            // Create the PropertySet.  This property bag contains all the value referenced in the expression.  We can
            // animation these property 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));

            // Set the parameters of the expression animation
            expressionAnimation.SetReferenceParameter("propertySet", _propertySet);
            expressionAnimation.SetReferenceParameter("visual", redSprite);

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


            // 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);
        }