大佬教程收集整理的这篇文章主要介绍了Silverlight之我见——制作星星闪烁动画,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; namespace RandEllipseSample { public partial class MainPage : UserControl { int shapesCount = 500; //图形数组的容量 //随机大小的上限 int theMaxW = 1300; int theMaxH = 720; Random rand = null; Storyboard story = null; Ellipse[] myShapes = null; public MainPage() { InitializeComponent(); rand = new Random(); story = new Storyboard(); story.Completed += new EventHandler(story_Completed); InitShapes(); InitAnimation(); //加载完成后马上播放动画 this.Loaded += new RoutedEventHandler(MainPage_Loaded); } void MainPage_Loaded(object sender,RoutedEventArgs E) { story.begin(); } void story_Completed(object sender,EventArgs E) { for (int x = 0; x < shapesCount; x++) { myShapes[x].Margin = new Thickness(Convert.ToDouble(rand.Next(0,theMaxW)),Convert.ToDouble(rand.Next(0,theMaxH)),0); } InitAnimation(); } /// <sumMary> /// 初始化形状数组 /// </sumMary> private void InitShapes() { myShapes = new Ellipse[shapesCount]; //实例化所有成员 for (int n = 0; n < shapesCount; n++) { myShapes[n] = new Ellipse(); myShapes[n].Fill = new SolidColorBrush(Colors.Transparent); myShapes[n].strokeThickness = 2d; //笔触为线性渐变 LinearGradientBrush gBrush = new LinearGradientBrush(); gBrush.StartPoint = new Point(0,0); gBrush.EndPoint = new Point(1,1); gBrush.GradientStops.Add(new GradientStop() { Color = Colors.Yellow,Offset = 0 }); gBrush.GradientStops.Add(new GradientStop() { Color = Colors.Red,Offset = 0.25 }); gBrush.GradientStops.Add(new GradientStop() { Color = Colors.White,Offset = 0.5 }); gBrush.GradientStops.Add(new GradientStop() { Color = Colors.blue,Offset = 0.75 }); myShapes[n].stroke = gBrush; //位置 myShapes[n].Margin = new Thickness(Convert.ToDouble(rand.Next(0,0); //大小 myShapes[n].Width = 10; myShapes[n].Height = 10; myShapes[n].HorizontalAlignment = HorizontalAlignment.Left; myShapes[n].VerticalAlignment = VerticalAlignment.Top; //加入可视化树 this.LayoutRoot.Children.Add(myShapes[n]); } } /// <sumMary> /// 初始化动画 /// </sumMary> private void InitAnimation() { story.Children.Clear(); for (int i = 0; i < shapesCount; i++) { int mSecond = rand.Next(0,5); //透明度 DoubleAnimation opacityAnimate = new DoubleAnimation(); opacityAnimate.From = 1.0; opacityAnimate.To = 0.0; Storyboard.SetTarget(opacityAnimate,myShapes[i]); Storyboard.SetTargetProperty(opacityAnimate,new PropertyPath("Opacity")); opacityAnimate.Duration = new Duration(TimeSpan.FromSeconds(mSecond)); opacityAnimate.RepeatBehavior = RepeatBehavior.Forever; //将时间线添加到情节摘要 story.Children.Add(opacityAnimatE); } } } } @H_618_49@
以上是大佬教程为你收集整理的Silverlight之我见——制作星星闪烁动画全部内容,希望文章能够帮你解决Silverlight之我见——制作星星闪烁动画所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。