def onClose(sender, args): global digits closeTimer.Stop() storyboard = Storyboard() def onCurrentStateInvalidated(sender, args): if sender.CurrentState == ClockState.Filling: for element in grid1.Children: element.Opacity = 0 storyboard.Remove(contentControl) tickTimer.Stop() window.Close() storyboard.CurrentStateInvalidated += onCurrentStateInvalidated r = Random(Environment.TickCount) for i in range(digits.Length): beginTime = Nullable[TimeSpan](TimeSpan.FromMilliseconds( r.Next(500))) for element in grid1.Children: if Grid.GetColumn(element) == i: doubleAnimation = DoubleAnimation( element.Opacity, 0, TimeSpan.FromMilliseconds(500)) doubleAnimation.BeginTime = beginTime sineEase = SineEase() sineEase.EasingMode = EasingMode.EaseIn doubleAnimation.EasingFunction = sineEase storyboard.Children.Add(doubleAnimation) Storyboard.SetTarget(doubleAnimation, element) Storyboard.SetTargetProperty( doubleAnimation, PropertyPath(UIElement.OpacityProperty)) contentControl.BeginStoryboard( storyboard, HandoffBehavior.SnapshotAndReplace, True) closeTimer.Tag = False
def onClose(sender, args): global digits closeTimer.Stop() storyboard = Storyboard() def onCurrentStateInvalidated(sender, args): if sender.CurrentState == ClockState.Filling: for element in grid1.Children: element.Opacity = 0 storyboard.Remove(contentControl) tickTimer.Stop() window.Close() storyboard.CurrentStateInvalidated += onCurrentStateInvalidated r = Random(Environment.TickCount) for i in range(digits.Length): beginTime = Nullable[TimeSpan](TimeSpan.FromMilliseconds(r.Next(500))) for element in grid1.Children: if Grid.GetColumn(element) == i: doubleAnimation = DoubleAnimation(element.Opacity, 0, TimeSpan.FromMilliseconds(500)) doubleAnimation.BeginTime = beginTime sineEase = SineEase() sineEase.EasingMode = EasingMode.EaseIn doubleAnimation.EasingFunction = sineEase storyboard.Children.Add(doubleAnimation) Storyboard.SetTarget(doubleAnimation, element) Storyboard.SetTargetProperty(doubleAnimation, PropertyPath(UIElement.OpacityProperty)) contentControl.BeginStoryboard(storyboard, HandoffBehavior.SnapshotAndReplace, True) closeTimer.Tag = False
def onLoaded(sender, args): time = 0 speed = task.Result.Value.Value.Key.Key * 1000 / 60 / 60 contentControl.Width = contentControl.ActualWidth * 1.5 if contentControl.ActualWidth > contentControl.ActualHeight else contentControl.ActualHeight * 1.5 contentControl.Height = contentControl.ActualWidth * 1.5 if contentControl.ActualWidth > contentControl.ActualHeight else contentControl.ActualHeight * 1.5 contentControl.RenderTransform.CenterX = contentControl.Width / 2 contentControl.RenderTransform.CenterY = contentControl.Height / 2 doubleAnimation1 = DoubleAnimation(contentControl.Opacity, 1, TimeSpan.FromMilliseconds(500)) doubleAnimation2 = DoubleAnimation(1.5, 1, TimeSpan.FromMilliseconds(500)) doubleAnimation3 = DoubleAnimation(1.5, 1, TimeSpan.FromMilliseconds(500)) doubleAnimation4 = DoubleAnimation(1, 0, TimeSpan.FromMilliseconds(500)) doubleAnimation5 = DoubleAnimation(1, 1.5, TimeSpan.FromMilliseconds(500)) doubleAnimation6 = DoubleAnimation(1, 1.5, TimeSpan.FromMilliseconds(500)) sineEase1 = SineEase() sineEase2 = SineEase() sineEase1.EasingMode = EasingMode.EaseOut sineEase2.EasingMode = EasingMode.EaseIn doubleAnimation1.EasingFunction = doubleAnimation2.EasingFunction = doubleAnimation3.EasingFunction = sineEase1 doubleAnimation4.EasingFunction = doubleAnimation5.EasingFunction = doubleAnimation6.EasingFunction = sineEase2 doubleAnimation4.BeginTime = Nullable[TimeSpan](TimeSpan.FromMilliseconds((250 * (max - 1) * 2 + 1000 + 3000) * task.Result.Value.Value.Value.Value.Count - 500)) doubleAnimation5.BeginTime = Nullable[TimeSpan](TimeSpan.FromMilliseconds((250 * (max - 1) * 2 + 1000 + 3000) * task.Result.Value.Value.Value.Value.Count - 500)) doubleAnimation6.BeginTime = Nullable[TimeSpan](TimeSpan.FromMilliseconds((250 * (max - 1) * 2 + 1000 + 3000) * task.Result.Value.Value.Value.Value.Count - 500)) storyboard.Children.Add(doubleAnimation1) storyboard.Children.Add(doubleAnimation2) storyboard.Children.Add(doubleAnimation3) storyboard.Children.Add(doubleAnimation4) storyboard.Children.Add(doubleAnimation5) storyboard.Children.Add(doubleAnimation6) Storyboard.SetTarget(doubleAnimation1, contentControl) Storyboard.SetTarget(doubleAnimation2, contentControl) Storyboard.SetTarget(doubleAnimation3, contentControl) Storyboard.SetTarget(doubleAnimation4, contentControl) Storyboard.SetTarget(doubleAnimation5, contentControl) Storyboard.SetTarget(doubleAnimation6, contentControl) Storyboard.SetTargetProperty(doubleAnimation1, PropertyPath(ContentControl.OpacityProperty)) Storyboard.SetTargetProperty(doubleAnimation2, PropertyPath("(0).(1)", ContentControl.RenderTransformProperty, ScaleTransform.ScaleXProperty)) Storyboard.SetTargetProperty(doubleAnimation3, PropertyPath("(0).(1)", ContentControl.RenderTransformProperty, ScaleTransform.ScaleYProperty)) Storyboard.SetTargetProperty(doubleAnimation4, PropertyPath(ContentControl.OpacityProperty)) Storyboard.SetTargetProperty(doubleAnimation5, PropertyPath("(0).(1)", ContentControl.RenderTransformProperty, ScaleTransform.ScaleXProperty)) Storyboard.SetTargetProperty(doubleAnimation6, PropertyPath("(0).(1)", ContentControl.RenderTransformProperty, ScaleTransform.ScaleYProperty)) for element1 in grid.Children: for element2 in element1.Children: w = element2.Width / 2 if speed > 15 else element2.Width / 2 * speed / 15; da1 = DoubleAnimation(element2.Opacity, 1, TimeSpan.FromMilliseconds(1000)) da2 = DoubleAnimation(-w if Convert.ToInt32(task.Result.Value.Value.Key.Value / 180) % 2 == 0 else w, 0, TimeSpan.FromMilliseconds(1000)) da3 = DoubleAnimation(1, 0, TimeSpan.FromMilliseconds(1000)) da4 = DoubleAnimation(0, w if Convert.ToInt32(task.Result.Value.Value.Key.Value / 180) % 2 == 0 else -w, TimeSpan.FromMilliseconds(1000)) se1 = SineEase() se2 = SineEase() da1.BeginTime = Nullable[TimeSpan](TimeSpan.FromMilliseconds(time + 250 * element2.Tag)) da2.BeginTime = Nullable[TimeSpan](TimeSpan.FromMilliseconds(time + 250 * element2.Tag)) da3.BeginTime = Nullable[TimeSpan](TimeSpan.FromMilliseconds(time + 250 * element2.Tag * 2 + 250 * (max - 1) - 250 * element2.Tag + 3000)) da4.BeginTime = Nullable[TimeSpan](TimeSpan.FromMilliseconds(time + 250 * element2.Tag * 2 + 250 * (max - 1) - 250 * element2.Tag + 3000)) se1.EasingMode = EasingMode.EaseOut se2.EasingMode = EasingMode.EaseIn da1.EasingFunction = da2.EasingFunction = se1 da3.EasingFunction = da4.EasingFunction = se2 storyboard.Children.Add(da1) storyboard.Children.Add(da2) storyboard.Children.Add(da3) storyboard.Children.Add(da4) Storyboard.SetTarget(da1, element2) Storyboard.SetTarget(da2, element2) Storyboard.SetTarget(da3, element2) Storyboard.SetTarget(da4, element2) Storyboard.SetTargetProperty(da1, PropertyPath(Rectangle.OpacityProperty)) Storyboard.SetTargetProperty(da2, PropertyPath("(0).(1)", Rectangle.RenderTransformProperty, TranslateTransform.XProperty)) Storyboard.SetTargetProperty(da3, PropertyPath(Rectangle.OpacityProperty)) Storyboard.SetTargetProperty(da4, PropertyPath("(0).(1)", Rectangle.RenderTransformProperty, TranslateTransform.XProperty)) time += 250 * (max - 1) + 1000 + 3000 storyboard.Begin()
def onLoaded(sender, args): time = 0 speed = task.Result.Value.Value.Key.Key * 1000 / 60 / 60 contentControl.Width = contentControl.ActualWidth * 1.5 if contentControl.ActualWidth > contentControl.ActualHeight else contentControl.ActualHeight * 1.5 contentControl.Height = contentControl.ActualWidth * 1.5 if contentControl.ActualWidth > contentControl.ActualHeight else contentControl.ActualHeight * 1.5 contentControl.RenderTransform.CenterX = contentControl.Width / 2 contentControl.RenderTransform.CenterY = contentControl.Height / 2 doubleAnimation1 = DoubleAnimation(contentControl.Opacity, 1, TimeSpan.FromMilliseconds(500)) doubleAnimation2 = DoubleAnimation(1.5, 1, TimeSpan.FromMilliseconds(500)) doubleAnimation3 = DoubleAnimation(1.5, 1, TimeSpan.FromMilliseconds(500)) doubleAnimation4 = DoubleAnimation(1, 0, TimeSpan.FromMilliseconds(500)) doubleAnimation5 = DoubleAnimation(1, 1.5, TimeSpan.FromMilliseconds(500)) doubleAnimation6 = DoubleAnimation(1, 1.5, TimeSpan.FromMilliseconds(500)) sineEase1 = SineEase() sineEase2 = SineEase() sineEase1.EasingMode = EasingMode.EaseOut sineEase2.EasingMode = EasingMode.EaseIn doubleAnimation1.EasingFunction = doubleAnimation2.EasingFunction = doubleAnimation3.EasingFunction = sineEase1 doubleAnimation4.EasingFunction = doubleAnimation5.EasingFunction = doubleAnimation6.EasingFunction = sineEase2 doubleAnimation4.BeginTime = Nullable[TimeSpan](TimeSpan.FromMilliseconds((250 * (max - 1) * 2 + 1000 + 3000) * task.Result.Value.Value.Value.Value.Count - 500)) doubleAnimation5.BeginTime = Nullable[TimeSpan](TimeSpan.FromMilliseconds((250 * (max - 1) * 2 + 1000 + 3000) * task.Result.Value.Value.Value.Value.Count - 500)) doubleAnimation6.BeginTime = Nullable[TimeSpan](TimeSpan.FromMilliseconds((250 * (max - 1) * 2 + 1000 + 3000) * task.Result.Value.Value.Value.Value.Count - 500)) storyboard.Children.Add(doubleAnimation1) storyboard.Children.Add(doubleAnimation2) storyboard.Children.Add(doubleAnimation3) storyboard.Children.Add(doubleAnimation4) storyboard.Children.Add(doubleAnimation5) storyboard.Children.Add(doubleAnimation6) Storyboard.SetTarget(doubleAnimation1, contentControl) Storyboard.SetTarget(doubleAnimation2, contentControl) Storyboard.SetTarget(doubleAnimation3, contentControl) Storyboard.SetTarget(doubleAnimation4, contentControl) Storyboard.SetTarget(doubleAnimation5, contentControl) Storyboard.SetTarget(doubleAnimation6, contentControl) Storyboard.SetTargetProperty(doubleAnimation1, PropertyPath(ContentControl.OpacityProperty)) Storyboard.SetTargetProperty(doubleAnimation2, PropertyPath("(0).(1)", ContentControl.RenderTransformProperty, ScaleTransform.ScaleXProperty)) Storyboard.SetTargetProperty(doubleAnimation3, PropertyPath("(0).(1)", ContentControl.RenderTransformProperty, ScaleTransform.ScaleYProperty)) Storyboard.SetTargetProperty(doubleAnimation4, PropertyPath(ContentControl.OpacityProperty)) Storyboard.SetTargetProperty(doubleAnimation5, PropertyPath("(0).(1)", ContentControl.RenderTransformProperty, ScaleTransform.ScaleXProperty)) Storyboard.SetTargetProperty(doubleAnimation6, PropertyPath("(0).(1)", ContentControl.RenderTransformProperty, ScaleTransform.ScaleYProperty)) for element1 in grid.Children: for element2 in element1.Children: w = element2.Width / 2 if speed > 15 else element2.Width / 2 * speed / 15; da1 = DoubleAnimation(element2.Opacity, 1, TimeSpan.FromMilliseconds(1000)) da2 = DoubleAnimation(-w if Convert.ToInt32(task.Result.Value.Value.Key.Value / 180) % 2 == 0 else w, 0, TimeSpan.FromMilliseconds(1000)) da3 = DoubleAnimation(1, 0, TimeSpan.FromMilliseconds(1000)) da4 = DoubleAnimation(0, w if Convert.ToInt32(task.Result.Value.Value.Key.Value / 180) % 2 == 0 else -w, TimeSpan.FromMilliseconds(1000)) se1 = SineEase() se2 = SineEase() da1.BeginTime = Nullable[TimeSpan](TimeSpan.FromMilliseconds(time + 250 * element2.Tag)) da2.BeginTime = Nullable[TimeSpan](TimeSpan.FromMilliseconds(time + 250 * element2.Tag)) da3.BeginTime = Nullable[TimeSpan](TimeSpan.FromMilliseconds(time + 250 * element2.Tag * 2 + 250 * (max - 1) - 250 * element2.Tag + 3000)) da4.BeginTime = Nullable[TimeSpan](TimeSpan.FromMilliseconds(time + 250 * element2.Tag * 2 + 250 * (max - 1) - 250 * element2.Tag + 3000)) se1.EasingMode = EasingMode.EaseOut se2.EasingMode = EasingMode.EaseIn da1.EasingFunction = da2.EasingFunction = se1 da3.EasingFunction = da4.EasingFunction = se2 storyboard.Children.Add(da1) storyboard.Children.Add(da2) storyboard.Children.Add(da3) storyboard.Children.Add(da4) Storyboard.SetTarget(da1, element2) Storyboard.SetTarget(da2, element2) Storyboard.SetTarget(da3, element2) Storyboard.SetTarget(da4, element2) Storyboard.SetTargetProperty(da1, PropertyPath(Rectangle.OpacityProperty)) Storyboard.SetTargetProperty(da2, PropertyPath("(0).(1)", Rectangle.RenderTransformProperty, TranslateTransform.XProperty)) Storyboard.SetTargetProperty(da3, PropertyPath(Rectangle.OpacityProperty)) Storyboard.SetTargetProperty(da4, PropertyPath("(0).(1)", Rectangle.RenderTransformProperty, TranslateTransform.XProperty)) time += 250 * (max - 1) + 1000 + 3000 storyboard.Begin()
def onLoaded(sender, args): global rectList, digits storyboard = Storyboard() def onCurrentStateInvalidated(sender, args): if sender.CurrentState == ClockState.Filling: for element in grid1.Children: element.Opacity = 1 storyboard.Remove(contentControl) if not grid1.Tag: closeTimer.Start() storyboard.CurrentStateInvalidated += onCurrentStateInvalidated r = Random(Environment.TickCount) dateTime = DateTime.Now digits[0] = dateTime.Hour / 10 digits[1] = dateTime.Hour % 10 digits[2] = dateTime.Minute / 10 digits[3] = dateTime.Minute % 10 digits[4] = dateTime.Second / 10 digits[5] = dateTime.Second % 10 for i in range(digits.Length): beginTime = Nullable[TimeSpan](TimeSpan.FromMilliseconds(r.Next(500))) for element1 in grid1.Children: if Grid.GetColumn(element1) == i: doubleAnimation = DoubleAnimation(element1.Opacity, 1, TimeSpan.FromMilliseconds(500)) doubleAnimation.BeginTime = beginTime sineEase = SineEase() sineEase.EasingMode = EasingMode.EaseOut doubleAnimation.EasingFunction = sineEase storyboard.Children.Add(doubleAnimation) Storyboard.SetTarget(doubleAnimation, element1) Storyboard.SetTargetProperty(doubleAnimation, PropertyPath(UIElement.OpacityProperty)) if Grid.GetRow(element1) == 0: scale1 = Math.Max(element1.ActualWidth / maxWidth, element1.ActualHeight / maxHeight) if rectList[digits[Grid.GetColumn(element1)]].Width > maxWidth and rectList[digits[Grid.GetColumn(element1)]].Height > maxHeight: translateX = Math.Round(-(rectList[digits[Grid.GetColumn(element1)]].X + (rectList[digits[Grid.GetColumn(element1)]].Width - maxWidth) / 2.0)) translateY = Math.Round(-(rectList[digits[Grid.GetColumn(element1)]].Y + (rectList[digits[Grid.GetColumn(element1)]].Height - maxHeight) / 2.0)) elif rectList[digits[Grid.GetColumn(element1)]].Width > maxWidth: translateX = Math.Round(-(rectList[digits[Grid.GetColumn(element1)]].X + (rectList[digits[Grid.GetColumn(element1)]].Width - maxWidth) / 2.0)) translateY = Math.Round(-rectList[digits[Grid.GetColumn(element1)]].Y) elif rectList[digits[Grid.GetColumn(element1)]].Height > maxHeight: translateX = Math.Round(-rectList[digits[Grid.GetColumn(element1)]].X) translateY = Math.Round(-(rectList[digits[Grid.GetColumn(element1)]].Y + (rectList[digits[Grid.GetColumn(element1)]].Height - maxHeight) / 2.0)) else: translateX = Math.Round(-rectList[digits[Grid.GetColumn(element1)]].X) translateY = Math.Round(-rectList[digits[Grid.GetColumn(element1)]].Y) scale2 = Math.Max(maxWidth / rectList[digits[Grid.GetColumn(element1)]].Width, maxHeight / rectList[digits[Grid.GetColumn(element1)]].Height) if scale2 > 1: scale2 = 1 for element2 in element1.Child.Children: transformGroup1 = TransformGroup() transformGroup1.Children.Add(TranslateTransform((element2.ActualWidth - maxWidth) / 2, (element2.ActualHeight - maxHeight) / 2)) transformGroup1.Children.Add(ScaleTransform(scale1, scale1, element2.ActualWidth / 2, element2.ActualHeight / 2)) element2.RenderTransform = transformGroup1 for element3 in element2.Children: transformGroup2 = TransformGroup() transformGroup2.Children.Add(TranslateTransform(translateX, translateY)) transformGroup2.Children.Add(ScaleTransform(scale2, scale2, maxWidth / 2, maxHeight / 2)) element3.RenderTransform = transformGroup2 contentControl.BeginStoryboard(storyboard, HandoffBehavior.SnapshotAndReplace, True) tickTimer.Start()
def onLoaded(sender, args): global rectList, digits storyboard = Storyboard() def onCurrentStateInvalidated(sender, args): if sender.CurrentState == ClockState.Filling: for element in grid1.Children: element.Opacity = 1 storyboard.Remove(contentControl) if not grid1.Tag: closeTimer.Start() storyboard.CurrentStateInvalidated += onCurrentStateInvalidated r = Random(Environment.TickCount) dateTime = DateTime.Now digits[0] = dateTime.Hour / 10 digits[1] = dateTime.Hour % 10 digits[2] = dateTime.Minute / 10 digits[3] = dateTime.Minute % 10 digits[4] = dateTime.Second / 10 digits[5] = dateTime.Second % 10 for i in range(digits.Length): beginTime = Nullable[TimeSpan](TimeSpan.FromMilliseconds( r.Next(500))) for element1 in grid1.Children: if Grid.GetColumn(element1) == i: doubleAnimation = DoubleAnimation( element1.Opacity, 1, TimeSpan.FromMilliseconds(500)) doubleAnimation.BeginTime = beginTime sineEase = SineEase() sineEase.EasingMode = EasingMode.EaseOut doubleAnimation.EasingFunction = sineEase storyboard.Children.Add(doubleAnimation) Storyboard.SetTarget(doubleAnimation, element1) Storyboard.SetTargetProperty( doubleAnimation, PropertyPath(UIElement.OpacityProperty)) if Grid.GetRow(element1) == 0: scale1 = Math.Max( element1.ActualWidth / maxWidth, element1.ActualHeight / maxHeight) if rectList[digits[Grid.GetColumn( element1 )]].Width > maxWidth and rectList[digits[ Grid.GetColumn( element1)]].Height > maxHeight: translateX = Math.Round( -(rectList[digits[Grid.GetColumn( element1)]].X + (rectList[digits[Grid.GetColumn( element1)]].Width - maxWidth) / 2.0)) translateY = Math.Round( -(rectList[digits[Grid.GetColumn( element1)]].Y + (rectList[digits[Grid.GetColumn( element1)]].Height - maxHeight) / 2.0)) elif rectList[digits[Grid.GetColumn( element1)]].Width > maxWidth: translateX = Math.Round( -(rectList[digits[Grid.GetColumn( element1)]].X + (rectList[digits[Grid.GetColumn( element1)]].Width - maxWidth) / 2.0)) translateY = Math.Round(-rectList[digits[ Grid.GetColumn(element1)]].Y) elif rectList[digits[Grid.GetColumn( element1)]].Height > maxHeight: translateX = Math.Round(-rectList[digits[ Grid.GetColumn(element1)]].X) translateY = Math.Round( -(rectList[digits[Grid.GetColumn( element1)]].Y + (rectList[digits[Grid.GetColumn( element1)]].Height - maxHeight) / 2.0)) else: translateX = Math.Round(-rectList[digits[ Grid.GetColumn(element1)]].X) translateY = Math.Round(-rectList[digits[ Grid.GetColumn(element1)]].Y) scale2 = Math.Max( maxWidth / rectList[digits[Grid.GetColumn( element1)]].Width, maxHeight / rectList[digits[Grid.GetColumn( element1)]].Height) if scale2 > 1: scale2 = 1 for element2 in element1.Child.Children: transformGroup1 = TransformGroup() transformGroup1.Children.Add( TranslateTransform( (element2.ActualWidth - maxWidth) / 2, (element2.ActualHeight - maxHeight) / 2)) transformGroup1.Children.Add( ScaleTransform( scale1, scale1, element2.ActualWidth / 2, element2.ActualHeight / 2)) element2.RenderTransform = transformGroup1 for element3 in element2.Children: transformGroup2 = TransformGroup() transformGroup2.Children.Add( TranslateTransform( translateX, translateY)) transformGroup2.Children.Add( ScaleTransform( scale2, scale2, maxWidth / 2, maxHeight / 2)) element3.RenderTransform = transformGroup2 contentControl.BeginStoryboard( storyboard, HandoffBehavior.SnapshotAndReplace, True) tickTimer.Start()