def onMouseLeftButtonUp(s, e): global y, storyboard if y is not None: if y > s.Top and storyboard is None: storyboard = Storyboard() da = DoubleAnimation(s.Top, y, TimeSpan.FromSeconds(Math.Sqrt(2 * ((y - s.Top) * 0.1) / 9.80665))) bounceEase = BounceEase() bounceEase.EasingMode = EasingMode.EaseOut bounceEase.Bounces = 5 da.EasingFunction = bounceEase def onCurrentStateInvalidated(sender, args): global storyboard if sender.CurrentState == ClockState.Filling: s.Top = da.To storyboard.Remove(s) storyboard = None storyboard.CurrentStateInvalidated += onCurrentStateInvalidated storyboard.Children.Add(da) Storyboard.SetTargetProperty(da, PropertyPath(Window.TopProperty)) s.BeginStoryboard(storyboard, HandoffBehavior.SnapshotAndReplace, True) y = None
def makeAnimation(top): xamlStr = """ <Storyboard xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> <DoubleAnimationUsingKeyFrames> <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="{0}"> <EasingDoubleKeyFrame.EasingFunction> <QuadraticEase EasingMode="EaseOut"/> </EasingDoubleKeyFrame.EasingFunction> </EasingDoubleKeyFrame> <EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="{1}"> <EasingDoubleKeyFrame.EasingFunction> <QuadraticEase EasingMode="EaseIn"/> </EasingDoubleKeyFrame.EasingFunction> </EasingDoubleKeyFrame> <EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="{2}"> <EasingDoubleKeyFrame.EasingFunction> <QuadraticEase EasingMode="EaseOut"/> </EasingDoubleKeyFrame.EasingFunction> </EasingDoubleKeyFrame> <EasingDoubleKeyFrame KeyTime="0:0:0.8" Value="{3}"> <EasingDoubleKeyFrame.EasingFunction> <QuadraticEase EasingMode="EaseIn"/> </EasingDoubleKeyFrame.EasingFunction> </EasingDoubleKeyFrame> </DoubleAnimationUsingKeyFrames> </Storyboard> """.format(top - 30, top, top - 30, top) sr = StringReader(xamlStr) sb = XamlServices.Load(sr) sr.Dispose() Storyboard.SetTarget(sb.Children[0], harriet.Window.Window) Storyboard.SetTargetProperty(sb.Children[0], PropertyPath("Top")) return sb
def _getStoryboardAppliedToWindowProperty(xamlStr, propertyPath): with StringReader(xamlStr) as sr: sb = XamlServices.Load(sr) Storyboard.SetTarget(sb.Children[0], harriet.Window.Window) Storyboard.SetTargetProperty(sb.Children[0], PropertyPath(propertyPath)) return sb
def _makeFadeStoryboard(start, end, duration): xamlStr = """ <Storyboard xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> <DoubleAnimation From="{0:.2f}" To="{1:.2f}" Duration="0:0:{2:.2f}" /> </Storyboard> """.format(start, end, duration) with StringReader(xamlStr) as sr: sb = XamlServices.Load(sr) Storyboard.SetTarget(sb.Children[0], harriet.Window.Window) Storyboard.SetTargetProperty(sb.Children[0], PropertyPath("(UIElement.Opacity)")) return sb
def makeEndAnimation(): xamlStr = """ <Storyboard xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> <DoubleAnimationUsingKeyFrames> <DiscreteDoubleKeyFrame KeyTime="0" Value="1"/> <EasingDoubleKeyFrame KeyTime="0:0:0.15" Value="1.2"> <EasingDoubleKeyFrame.EasingFunction> <QuadraticEase EasingMode="EaseOut"/> </EasingDoubleKeyFrame.EasingFunction> </EasingDoubleKeyFrame> <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="1.0"> <EasingDoubleKeyFrame.EasingFunction> <QuadraticEase EasingMode="EaseIn"/> </EasingDoubleKeyFrame.EasingFunction> </EasingDoubleKeyFrame> </DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames> <DiscreteDoubleKeyFrame KeyTime="0" Value="1"/> <EasingDoubleKeyFrame KeyTime="0:0:0.15" Value="0.84"> <EasingDoubleKeyFrame.EasingFunction> <QuadraticEase EasingMode="EaseOut"/> </EasingDoubleKeyFrame.EasingFunction> </EasingDoubleKeyFrame> <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="1.0"> <EasingDoubleKeyFrame.EasingFunction> <QuadraticEase EasingMode="EaseIn"/> </EasingDoubleKeyFrame.EasingFunction> </EasingDoubleKeyFrame> </DoubleAnimationUsingKeyFrames> </Storyboard> """ sr = StringReader(xamlStr) sb = XamlServices.Load(sr) sr.Dispose() #FIXME: 入れる先が用意されてないのでダメ Storyboard.SetTarget(sb.Children[0], harriet.Character) Storyboard.SetTarget(sb.Children[1], harriet.Character) Storyboard.SetTargetProperty( sb.Children[0], PropertyPath("RenderTransform.Children[2].ScaleX")) Storyboard.SetTargetProperty( sb.Children[1], PropertyPath("RenderTransform.Children[2].ScaleY")) return sb
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 onCompleted(task): global idList if task.Result.Key.Count > 0: sequenceList = List[Sequence]() for sequence in Script.Instance.Sequences: if sequence.Name.Equals("Weather"): sequenceList.Add(sequence) for s in task.Result.Key: Script.Instance.TryEnqueue(Script.Instance.Prepare(sequenceList, s)) if Application.Current.MainWindow.IsVisible and task.Result.Value.Value.Value.Value.Count > 0 and not Enumerable.SequenceEqual[Double](idList, task.Result.Value.Value.Value.Key): width = 128 height = 128 max = 4 window = Window() contentControl = ContentControl() grid = Grid() storyboard = Storyboard() def onCurrentStateInvalidated(sender, args): if sender.CurrentState == ClockState.Filling: window.Close() storyboard.CurrentStateInvalidated += onCurrentStateInvalidated 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() fs = None bi = BitmapImage() try: fs = FileStream("Assets\\Background-Popup.png", FileMode.Open, FileAccess.Read, FileShare.Read) bi.BeginInit() bi.StreamSource = fs bi.CacheOption = BitmapCacheOption.OnLoad bi.CreateOptions = BitmapCreateOptions.None bi.EndInit() finally: if fs is not None: fs.Close() window.Owner = Application.Current.MainWindow window.Title = Application.Current.MainWindow.Title window.WindowStartupLocation = WindowStartupLocation.CenterOwner window.AllowsTransparency = True window.WindowStyle = WindowStyle.None window.ResizeMode = ResizeMode.NoResize window.ShowActivated = False window.ShowInTaskbar = Application.Current.MainWindow.ContextMenu.Items[5].IsChecked window.Topmost = True window.SizeToContent = SizeToContent.WidthAndHeight window.Background = Brushes.Transparent window.Loaded += onLoaded contentControl.UseLayoutRounding = True contentControl.HorizontalAlignment = HorizontalAlignment.Stretch contentControl.VerticalAlignment = VerticalAlignment.Stretch contentControl.Opacity = 0 contentControl.RenderTransform = ScaleTransform(1, 1) window.Content = contentControl imageBrush = ImageBrush(bi) imageBrush.TileMode = TileMode.None imageBrush.Stretch = Stretch.Fill imageBrush.ViewboxUnits = BrushMappingMode.Absolute imageBrush.Viewbox = Rect(0, 0, bi.Width, bi.Height) imageBrush.AlignmentX = AlignmentX.Left imageBrush.AlignmentY = AlignmentY.Top imageBrush.Opacity = 0.5 dg = DrawingGroup() dc = dg.Open() dc.DrawRectangle(SolidColorBrush(Color.FromArgb(Byte.MaxValue * 50 / 100, 0, 0, 0)), None, Rect(0, 0, bi.Width, bi.Height)) dc.DrawRectangle(imageBrush, None, Rect(0, 0, bi.Width, bi.Height)) dc.Close() backgroundBrush = ImageBrush(DrawingImage(dg)) backgroundBrush.TileMode = TileMode.Tile backgroundBrush.ViewportUnits = BrushMappingMode.Absolute backgroundBrush.Viewport = Rect(0, 0, bi.Width, bi.Height) backgroundBrush.Stretch = Stretch.None if backgroundBrush.CanFreeze: backgroundBrush.Freeze() grid.HorizontalAlignment = HorizontalAlignment.Stretch grid.VerticalAlignment = VerticalAlignment.Stretch grid.Background = backgroundBrush grid.Width = 150 grid.Height = 150 grid.Clip = EllipseGeometry(Rect(0, 0, 150, 150)) dropShadowEffect = DropShadowEffect() dropShadowEffect.BlurRadius = 1 dropShadowEffect.Color = Colors.Black dropShadowEffect.Direction = 270 dropShadowEffect.Opacity = 0.5 dropShadowEffect.ShadowDepth = 1 if dropShadowEffect.CanFreeze: dropShadowEffect.Freeze() grid.Effect = dropShadowEffect contentControl.Content = grid solidColorBrush = SolidColorBrush(colorFromAhsb(Byte.MaxValue, 60, 1.0, 1.0) if task.Result.Value.Key < 0 else colorFromAhsb(Byte.MaxValue, 0, 1.0, 0.4) if task.Result.Value.Key > 37 else colorFromAhsb(Byte.MaxValue, 60 - 60 * task.Result.Value.Key / 37, 1.0, 0.4 + 0.6 * Math.Pow(Math.E, (37 / 5 - task.Result.Value.Key) - 37 / 5) if task.Result.Value.Key < 37 / 5 else 0.4)) if solidColorBrush.CanFreeze: solidColorBrush.Freeze() for stream in task.Result.Value.Value.Value.Value: try: bi = BitmapImage() bi.BeginInit() bi.StreamSource = stream bi.CacheOption = BitmapCacheOption.OnLoad bi.CreateOptions = BitmapCreateOptions.None bi.EndInit() finally: stream.Close() imageBrush = ImageBrush(bi) imageBrush.TileMode = TileMode.None imageBrush.ViewportUnits = BrushMappingMode.Absolute imageBrush.Viewport = Rect(0, 0, width, height) imageBrush.Stretch = Stretch.Uniform if imageBrush.CanFreeze: imageBrush.Freeze() g = Grid() g.HorizontalAlignment = HorizontalAlignment.Center g.VerticalAlignment = VerticalAlignment.Center g.Background = Brushes.Transparent g.Width = width g.Height = height grid.Children.Add(g) for i in range(max): rectangle = Rectangle() rectangle.HorizontalAlignment = HorizontalAlignment.Left rectangle.VerticalAlignment = VerticalAlignment.Top rectangle.Width = width rectangle.Height = height rectangle.Fill = solidColorBrush rectangle.Opacity = 0 rectangle.OpacityMask = imageBrush rectangle.Clip = RectangleGeometry(Rect(0, height / max * i, width, height / max)) rectangle.RenderTransform = TranslateTransform(0, 0) rectangle.Tag = i g.Children.Add(rectangle) window.Show() idList.Clear() idList.AddRange(task.Result.Value.Value.Value.Key)
DoubleAnimation, Storyboard ) root = Canvas() Application.Current.RootVisual = root root.Children.Clear() root.Resources.Clear() t = TextBlock() t.FontSize = 20 t.Text = 'Move the Mouse Over Me' root.Children.Add(t) sb = Storyboard() duration = Duration(TimeSpan.FromSeconds(0.25)) a = DoubleAnimation() a.Duration = duration sb.Duration = duration sb.AutoReverse = True sb.Children.Add(a) Storyboard.SetTarget(a, t) Storyboard.SetTargetProperty(a, PropertyPath('FontSize')) a.From = 20 a.To = 30 def anim(s, e): print 'Starting' sb.Begin()
def onTick(sender, args): global rectList, digits if rectList.Count > 0: dateTime = DateTime.Now for element1 in grid1.Children: if Grid.GetRow(element1) == 0: if Grid.GetColumn(element1) == 0: digit = dateTime.Hour / 10 elif Grid.GetColumn(element1) == 1: digit = dateTime.Hour % 10 elif Grid.GetColumn(element1) == 2: digit = dateTime.Minute / 10 elif Grid.GetColumn(element1) == 3: digit = dateTime.Minute % 10 elif Grid.GetColumn(element1) == 4: digit = dateTime.Second / 10 else: digit = dateTime.Second % 10 if digit != digits[Grid.GetColumn(element1)]: for element2 in element1.Child.Children: for element3 in element2.Children: storyboard = Storyboard() for transform in element3.RenderTransform.Children: if clr.GetClrType( TranslateTransform ).IsInstanceOfType(transform): if rectList[ digit].Width > maxWidth and rectList[ digit].Height > maxHeight: translateX = Math.Round(-( rectList[digits[ Grid.GetColumn( element1)]].X + (rectList[digit].X + (rectList[digit].Width - maxWidth) / 2.0 - rectList[digits[ Grid.GetColumn( element1)]].X) )) translateY = Math.Round(-( rectList[digits[ Grid.GetColumn( element1)]].Y + (rectList[digit].Y + (rectList[digit]. Height - maxHeight) / 2.0 - rectList[digits[ Grid.GetColumn( element1)]].Y) )) elif rectList[ digit].Width > maxWidth: translateX = Math.Round(-( rectList[digits[ Grid.GetColumn( element1)]].X + (rectList[digit].X + (rectList[digit].Width - maxWidth) / 2.0 - rectList[digits[ Grid.GetColumn( element1)]].X) )) translateY = Math.Round(-( rectList[digits[ Grid.GetColumn( element1)]].Y + (rectList[digit].Y - rectList[digits[ Grid.GetColumn( element1)]].Y) )) elif rectList[ digit].Height > maxHeight: translateX = Math.Round(-( rectList[digits[ Grid.GetColumn( element1)]].X + (rectList[digit].X - rectList[digits[ Grid.GetColumn( element1)]].X) )) translateY = Math.Round(-( rectList[digits[ Grid.GetColumn( element1)]].Y + (rectList[digit].Y + (rectList[digit]. Height - maxHeight) / 2.0 - rectList[digits[ Grid.GetColumn( element1)]].Y) )) else: translateX = Math.Round(-( rectList[digits[ Grid.GetColumn( element1)]].X + (rectList[digit].X - rectList[digits[ Grid.GetColumn( element1)]].X) )) translateY = Math.Round(-( rectList[digits[ Grid.GetColumn( element1)]].Y + (rectList[digit].Y - rectList[digits[ Grid.GetColumn( element1)]].Y) )) doubleAnimation1 = DoubleAnimation( translateX, TimeSpan.FromMilliseconds( 500)) doubleAnimation2 = DoubleAnimation( translateY, TimeSpan.FromMilliseconds( 500)) sineEase = SineEase() sineEase.EasingMode = EasingMode.EaseInOut doubleAnimation1.EasingFunction = sineEase doubleAnimation2.EasingFunction = sineEase storyboard.Children.Add( doubleAnimation1) storyboard.Children.Add( doubleAnimation2) Storyboard.SetTarget( doubleAnimation1, element3) Storyboard.SetTarget( doubleAnimation2, element3) Storyboard.SetTargetProperty( doubleAnimation1, PropertyPath( "(0).(1)[0].(2)", Canvas. RenderTransformProperty, TransformGroup. ChildrenProperty, TranslateTransform. XProperty)) Storyboard.SetTargetProperty( doubleAnimation2, PropertyPath( "(0).(1)[0].(2)", Canvas. RenderTransformProperty, TransformGroup. ChildrenProperty, TranslateTransform. YProperty)) else: scale1 = Math.Max( maxWidth / rectList[digits[ Grid.GetColumn( element1)]].Width, maxHeight / rectList[ digits[Grid.GetColumn( element1)]].Height) scale2 = Math.Max( maxWidth / rectList[digit].Width, maxHeight / rectList[digit].Height) if scale1 > 1: scale1 = 1 if scale2 > 1: scale2 = 1 transform.ScaleX = transform.ScaleY = scale1 + ( scale2 - scale1) doubleAnimation1 = DoubleAnimation( scale1 + (scale2 - scale1), TimeSpan.FromMilliseconds( 500)) doubleAnimation2 = DoubleAnimation( scale1 + (scale2 - scale1), TimeSpan.FromMilliseconds( 500)) sineEase = SineEase() sineEase.EasingMode = EasingMode.EaseInOut doubleAnimation1.EasingFunction = sineEase doubleAnimation2.EasingFunction = sineEase storyboard.Children.Add( doubleAnimation1) storyboard.Children.Add( doubleAnimation2) Storyboard.SetTarget( doubleAnimation1, element3) Storyboard.SetTarget( doubleAnimation2, element3) Storyboard.SetTargetProperty( doubleAnimation1, PropertyPath( "(0).(1)[1].(2)", Canvas. RenderTransformProperty, TransformGroup. ChildrenProperty, ScaleTransform. ScaleXProperty)) Storyboard.SetTargetProperty( doubleAnimation2, PropertyPath( "(0).(1)[1].(2)", Canvas. RenderTransformProperty, TransformGroup. ChildrenProperty, ScaleTransform. ScaleYProperty)) element3.BeginStoryboard( storyboard, HandoffBehavior.SnapshotAndReplace) digits[Grid.GetColumn(element1)] = digit
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()