Seek() public méthode

public Seek ( [ offset ) : void
offset [
Résultat void
        public async Task<int> CreateCloud(bool isInitial) {
            var cloud = new Image {
                Source = new BitmapImage(new Uri("ms-appx:/Assets/BackgroundClouds.png")),
                Width = Random.Next(800, 2000),
                Stretch = Stretch.Uniform,
                Visibility = Visibility.Collapsed
            };

            Children.Add(cloud);

            await cloud.WaitForNonZeroSizeAsync();

            var cloudYMax = (int)(ActualHeight - cloud.ActualHeight / 2);
            var cloudY = TopMargin > cloudYMax
                ? TopMargin
                : Random.Next(TopMargin, cloudYMax);

            SetTop(cloud, cloudY);
            SetZIndex(cloud, (int)cloud.Width);

            var time = BaseTime * 1000 + (int)(Random.NextDouble() * RandomTime * 1000);

            var from = (int)(-cloud.Width);
            var to = (int)ActualWidth;

            SetLeft(cloud, from);

            var storyboard = new Storyboard();
            var animation = new DoubleAnimation {
                AutoReverse = false,
                Duration = new Duration(TimeSpan.FromMilliseconds(time)),
                RepeatBehavior = new RepeatBehavior(1),
                From = from,
                To = to,
                EnableDependentAnimation = true,
            };
            animation.Completed += delegate {
                Children.Remove(cloud);
            };
            storyboard.Children.Add(animation);
            Storyboard.SetTarget(animation, cloud);
            Storyboard.SetTargetProperty(animation, "(Canvas.Left)");

            Resources.Add(Guid.NewGuid().ToString(), storyboard);

            storyboard.Begin();

            if (isInitial) {
                storyboard.Seek(TimeSpan.FromMilliseconds(Random.Next(0, time)));
            }

            cloud.Visibility = Visibility.Visible;

            return time;
        }
        private async void OnBorderTapped(object sender, TappedRoutedEventArgs e)
        {
            if (_inAnimation)
            {
                return;
            }

            _inAnimation = true;
            _onBorderTappedCall++;
            var currentCall = _onBorderTappedCall;
            //var border = (Border)sender;
            //var grid = border.GetFirstAncestorOfType<UniformGrid>();

            //var sb = new Storyboard();

            //var beginTime = TimeSpan.Zero;

            //if (_isArrangedInGrid)
            //{
            //    var center = new Point(
            //        (grid.ActualWidth - border.ActualWidth) / 2,
            //        (grid.ActualHeight - border.ActualHeight) / 2);

            //    foreach (var child in grid.Children)
            //    {
            //        child.RenderTransform = new CompositeTransform();
            //        var nc = (NamedColor)((FrameworkElement)child).DataContext;
            //        var hsv = nc.Color.ToHsv();
            //        var targetX = center.X + center.X * Math.Sin(hsv.H * Math.PI / 180) * (0.25 + 0.75 * hsv.V);
            //        var targetY = center.Y - center.Y * Math.Cos(hsv.H * Math.PI / 180) * (0.25 + 0.75 * hsv.V);
            //        var actualPosition = child.TransformToVisual(grid).TransformPoint(new Point(0, 0));
            //        //Debug.WriteLine(actualPosition);
            //        var deltaX = targetX - actualPosition.X;
            //        var deltaY = targetY - actualPosition.Y;

            //        var xa = new DoubleAnimation();
            //        xa.BeginTime = beginTime;
            //        xa.Duration = TimeSpan.FromSeconds(1);
            //        xa.To = deltaX;
            //        Storyboard.SetTarget(xa, child.RenderTransform);
            //        Storyboard.SetTargetProperty(xa, "TranslateX");
            //        sb.Children.Add(xa);

            //        var ya = new DoubleAnimation();
            //        ya.BeginTime = beginTime;
            //        ya.Duration = TimeSpan.FromSeconds(1);
            //        ya.To = deltaY;
            //        Storyboard.SetTarget(ya, child.RenderTransform);
            //        Storyboard.SetTargetProperty(ya, "TranslateY");
            //        sb.Children.Add(ya);

            //        var aa = new DoubleAnimation();
            //        aa.BeginTime = beginTime;
            //        aa.Duration = TimeSpan.FromSeconds(1);
            //        aa.To = hsv.H;
            //        Storyboard.SetTarget(aa, child.RenderTransform);
            //        Storyboard.SetTargetProperty(aa, "Rotation");
            //        sb.Children.Add(aa);

            //        beginTime += TimeSpan.FromMilliseconds(5);
            //    }
            //}
            //else
            //{
            //    foreach (var child in grid.Children)
            //    {
            //        var nc = (NamedColor)((FrameworkElement)child).DataContext;

            //        var xa = new DoubleAnimation();
            //        xa.BeginTime = beginTime;
            //        xa.Duration = TimeSpan.FromSeconds(1);
            //        xa.To = 0;
            //        Storyboard.SetTarget(xa, child.RenderTransform);
            //        Storyboard.SetTargetProperty(xa, "TranslateX");
            //        sb.Children.Add(xa);

            //        var ya = new DoubleAnimation();
            //        ya.BeginTime = beginTime;
            //        ya.Duration = TimeSpan.FromSeconds(1);
            //        ya.To = 0;
            //        Storyboard.SetTarget(ya, child.RenderTransform);
            //        Storyboard.SetTargetProperty(ya, "TranslateY");
            //        sb.Children.Add(ya);

            //        var aa = new DoubleAnimation();
            //        aa.BeginTime = beginTime;
            //        aa.Duration = TimeSpan.FromSeconds(1);
            //        aa.To = 0;
            //        Storyboard.SetTarget(aa, child.RenderTransform);
            //        Storyboard.SetTargetProperty(aa, "Rotation");
            //        sb.Children.Add(aa);

            //        beginTime += TimeSpan.FromMilliseconds(5);
            //    }
            //}

            //sb.Begin();
            //_isArrangedInGrid = !_isArrangedInGrid;

            var border = (Border)sender;
            var grid = border.GetFirstAncestorOfType<UniformGrid>();

            if (_isArrangedInGrid)
            {
                var center = new Point(
                    (grid.ActualWidth - border.ActualWidth) / 2,
                    (grid.ActualHeight - border.ActualHeight) / 2);

                {
                    var sb1 = new Storyboard();

                    var beginTime = TimeSpan.Zero;

                    foreach (var child in grid.Children)
                    {
                        child.RenderTransform = new CompositeTransform();
                        child.RenderTransformOrigin = new Point(0.5, 0.5); 
                        var nc = (NamedColor)((FrameworkElement)child).DataContext;
                        var hsv = nc.Color.ToHsl();
                        var targetX = center.X +
                                        center.X * Math.Sin(hsv.H * Math.PI / 180) *
                                        (0.25 + 0.75 * Math.Min(hsv.L, hsv.S));
                        var targetY = center.Y -
                                        center.Y * Math.Cos(hsv.H * Math.PI / 180) *
                                        (0.25 + 0.75 * Math.Min(hsv.L, hsv.S));
                        var actualPosition =
                            child.TransformToVisual(grid)
                                    .TransformPoint(new Point(0, 0));
                        //Debug.WriteLine(actualPosition);
                        var deltaX = targetX - actualPosition.X;
                        var deltaY = targetY - actualPosition.Y;

                        var xa = new DoubleAnimation();
                        xa.BeginTime = beginTime;
                        xa.Duration = TimeSpan.FromSeconds(1);
                        xa.To = deltaX;
                        Storyboard.SetTarget(xa, child.RenderTransform);
                        Storyboard.SetTargetProperty(xa, "TranslateX");
                        sb1.Children.Add(xa);

                        var ya = new DoubleAnimation();
                        ya.BeginTime = beginTime;
                        ya.Duration = TimeSpan.FromSeconds(1);
                        ya.To = deltaY;
                        Storyboard.SetTarget(ya, child.RenderTransform);
                        Storyboard.SetTargetProperty(ya, "TranslateY");
                        sb1.Children.Add(ya);

                        var aa = new DoubleAnimation();
                        aa.BeginTime = beginTime;
                        aa.Duration = TimeSpan.FromSeconds(1);
                        aa.To = hsv.H;
                        Storyboard.SetTarget(aa, child.RenderTransform);
                        Storyboard.SetTargetProperty(aa, "Rotation");
                        sb1.Children.Add(aa);
                    }

                    await sb1.BeginAsync();
                }

                if (currentCall != _onBorderTappedCall)
                {
                    return;
                }

                const double revolutionDurationInS = 30d;

                foreach (var child in grid.Children)
                {
                    child.RenderTransform = new CompositeTransform();
                    child.RenderTransformOrigin = new Point(0.5, 0.5); 
                    var nc = (NamedColor)((FrameworkElement)child).DataContext;
                    var hsv = nc.Color.ToHsl();
                    var actualPosition = child.TransformToVisual(grid).TransformPoint(new Point(0, 0));

                    var sb = new Storyboard();
                    sb.RepeatBehavior = RepeatBehavior.Forever;

                    var minX = center.X - center.X * (0.25 + 0.75 * Math.Min(hsv.L, hsv.S)) - actualPosition.X;
                    var midX = center.X - actualPosition.X;
                    var maxX = center.X + center.X * (0.25 + 0.75 * Math.Min(hsv.L, hsv.S)) - actualPosition.X;
                    var minY = center.Y - center.Y * (0.25 + 0.75 * Math.Min(hsv.L, hsv.S)) - actualPosition.Y;
                    var midY = center.Y - actualPosition.Y;
                    var maxY = center.Y + center.Y * (0.25 + 0.75 * Math.Min(hsv.L, hsv.S)) - actualPosition.Y;

                    var xa = new DoubleAnimationUsingKeyFrames();
                    xa.KeyFrames.Add(new DiscreteDoubleKeyFrame { KeyTime = TimeSpan.Zero, Value = midX});
                    xa.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(revolutionDurationInS * 0.25), Value = maxX, EasingFunction = new SineEase { EasingMode = EasingMode.EaseOut } });
                    xa.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(revolutionDurationInS * 0.50), Value = midX, EasingFunction = new SineEase { EasingMode = EasingMode.EaseIn } });
                    xa.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(revolutionDurationInS * 0.75), Value = minX, EasingFunction = new SineEase { EasingMode = EasingMode.EaseOut } });
                    xa.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(revolutionDurationInS * 1.00), Value = midX, EasingFunction = new SineEase { EasingMode = EasingMode.EaseIn } });
                    Storyboard.SetTarget(xa, child.RenderTransform);
                    Storyboard.SetTargetProperty(xa, "TranslateX");
                    sb.Children.Add(xa);

                    var ya = new DoubleAnimationUsingKeyFrames();
                    ya.KeyFrames.Add(new DiscreteDoubleKeyFrame { KeyTime = TimeSpan.Zero, Value = minY });
                    ya.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(revolutionDurationInS * 0.25), Value = midY, EasingFunction = new SineEase { EasingMode = EasingMode.EaseIn } });
                    ya.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(revolutionDurationInS * 0.50), Value = maxY, EasingFunction = new SineEase { EasingMode = EasingMode.EaseOut } });
                    ya.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(revolutionDurationInS * 0.75), Value = midY, EasingFunction = new SineEase { EasingMode = EasingMode.EaseIn } });
                    ya.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(revolutionDurationInS * 1.00), Value = minY, EasingFunction = new SineEase { EasingMode = EasingMode.EaseOut } });
                    Storyboard.SetTarget(ya, child.RenderTransform);
                    Storyboard.SetTargetProperty(ya, "TranslateY");
                    sb.Children.Add(ya);

                    var aa = new DoubleAnimation();
                    aa.Duration = TimeSpan.FromSeconds(revolutionDurationInS);
                    aa.From = 0;
                    aa.To = 360;
                    Storyboard.SetTarget(aa, child.RenderTransform);
                    Storyboard.SetTargetProperty(aa, "Rotation");
                    sb.Children.Add(aa);
                    //sb.BeginTime =
                    //    TimeSpan.FromSeconds(hsv.H * revolutionDurationInS / 360d);
                    sb.Begin();
                    sb.Seek(TimeSpan.FromSeconds(((hsv.H + 360) % 360) * revolutionDurationInS / 360d));
                }
            }
            else
            {
                var sb = new Storyboard();
                var beginTime = TimeSpan.Zero;

                foreach (var child in grid.Children)
                {
                    //var nc = (NamedColor)((FrameworkElement)child).DataContext;

                    var xa = new DoubleAnimation();
                    xa.BeginTime = beginTime;
                    xa.Duration = TimeSpan.FromSeconds(1);
                    xa.To = 0;
                    Storyboard.SetTarget(xa, child.RenderTransform);
                    Storyboard.SetTargetProperty(xa, "TranslateX");
                    sb.Children.Add(xa);

                    var ya = new DoubleAnimation();
                    ya.BeginTime = beginTime;
                    ya.Duration = TimeSpan.FromSeconds(1);
                    ya.To = 0;
                    Storyboard.SetTarget(ya, child.RenderTransform);
                    Storyboard.SetTargetProperty(ya, "TranslateY");
                    sb.Children.Add(ya);

                    var aa = new DoubleAnimation();
                    aa.BeginTime = beginTime;
                    aa.Duration = TimeSpan.FromSeconds(1);
                    aa.To = 0;
                    Storyboard.SetTarget(aa, child.RenderTransform);
                    Storyboard.SetTargetProperty(aa, "Rotation");
                    sb.Children.Add(aa);

                    //beginTime += TimeSpan.FromMilliseconds(5);
                }

                await sb.BeginAsync();
            }

            _isArrangedInGrid = !_isArrangedInGrid;
            _inAnimation = false;
        }