写了一个整人程序,较简单,有兴趣者可以看看

程序是基于WPF开发的,动态创建对象和动画。

 

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Windows;  
  6. using System.Windows.Controls;  
  7. using System.Windows.Data;  
  8. using System.Windows.Documents;  
  9. using System.Windows.Input;  
  10. using System.Windows.Media;  
  11. using System.Windows.Media.Imaging;  
  12. using System.Windows.Navigation;  
  13. using System.Windows.Shapes;  
  14. using System.Windows.Media.Animation;   
  15. namespace WpfApplication1  
  16. {  
  17.     /// <summary>  
  18.     /// Window1.xaml 的交互逻辑  
  19.     /// </summary>  
  20.     public partial class Window1 : Window  
  21.     {  
  22.         Ellipse[] els1, els2;  
  23.         Storyboard std, std2;  
  24.         int theMax = 100;  
  25.         public Window1()  
  26.         {  
  27.             InitializeComponent();  
  28.             this.Title = "哈哈,看好了";  
  29.             this.WindowState = WindowState.Maximized;  
  30.             els1 = new Ellipse[theMax];  
  31.             els2 = new Ellipse[theMax];  
  32.             for (int n = 0; n < theMax; n++)  
  33.             {  
  34.                 els1[n] = new Ellipse();  
  35.                 els1[n].Fill = Brushes.Transparent;  
  36.                 els1[n].Stroke = Brushes.Black;  
  37.                 els1[n].StrokeThickness = 0.55;  
  38.                 els1[n].Width = 0;  
  39.                 els1[n].Height = 0;  
  40.                 els1[n].HorizontalAlignment = HorizontalAlignment.Center;  
  41.                 els1[n].VerticalAlignment = VerticalAlignment.Center;  
  42.                 //els1[n].Stretch = Stretch.Fill;  
  43.                 this.Root.Children.Add(els1[n]);  
  44.             }  
  45.               
  46.             for (int s = 0; s < theMax; s++)  
  47.             {  
  48.                 els2[s] = new Ellipse();  
  49.                 els2[s].Fill = Brushes.Transparent;  
  50.                 els2[s].Stroke = Brushes.Black;  
  51.                 els2[s].StrokeThickness = 0.45;  
  52.                 //els2[s].Width = 1300;  
  53.                 //els2[s].Height = 970;  
  54.                 els2[s].Margin = new Thickness(-150);  
  55.                 this.Root.Children.Add(els2[s]);  
  56.             }   
  57.             std = new Storyboard();  
  58.             std.RepeatBehavior = RepeatBehavior.Forever;   
  59.             Duration AllDuration = new Duration(TimeSpan.FromSeconds(1.2));  
  60.             //std.Duration = AllDuration;  
  61.             for (int k = 0; k < theMax; k++)  
  62.             {  
  63.                 DoubleAnimation dan = new DoubleAnimation();  
  64.                 dan.BeginTime = TimeSpan.FromSeconds(0.02 * k);  
  65.                 dan.Duration = AllDuration;  
  66.                 dan.From = 0;  
  67.                 dan.To = 1100;  
  68.                 dan.RepeatBehavior = RepeatBehavior.Forever;  
  69.                 Storyboard.SetTarget(dan, els1[k]);  
  70.                 Storyboard.SetTargetProperty(dan, new PropertyPath("(FrameworkElement.Width)"));  
  71.                 std.Children.Add(dan);  
  72.                 dan = new DoubleAnimation();  
  73.                 dan.BeginTime = TimeSpan.FromSeconds(0.02 * k);  
  74.                 dan.Duration = AllDuration;  
  75.                 dan.From = 0;  
  76.                 dan.To = 1000;  
  77.                 dan.RepeatBehavior = RepeatBehavior.Forever;  
  78.                 Storyboard.SetTarget(dan, els1[k]);  
  79.                 Storyboard.SetTargetProperty(dan, new PropertyPath("(FrameworkElement.Height)"));  
  80.                 std.Children.Add(dan);  
  81.             }   
  82.             //2  
  83.             std2 = new Storyboard();  
  84.             std2.RepeatBehavior = RepeatBehavior.Forever;  
  85.             for (int e = 0; e < theMax; e++)  
  86.             {  
  87.                 DoubleAnimation dan = new DoubleAnimation();  
  88.                 dan.BeginTime = TimeSpan.FromSeconds(0.05 * e);  
  89.                 dan.Duration = AllDuration;  
  90.                 dan.From = 1100;  
  91.                 dan.To = 0;  
  92.                 dan.RepeatBehavior = RepeatBehavior.Forever;  
  93.                 Storyboard.SetTarget(dan, els2[e]);  
  94.                 Storyboard.SetTargetProperty(dan, new PropertyPath("(FrameworkElement.Width)"));  
  95.                 std2.Children.Add(dan);  
  96.                 dan = new DoubleAnimation();  
  97.                 dan.BeginTime = TimeSpan.FromSeconds(0.03 * e);  
  98.                 dan.Duration = AllDuration;  
  99.                 dan.From = 1350;  
  100.                 dan.To = 0;  
  101.                 dan.RepeatBehavior = RepeatBehavior.Forever;  
  102.                 Storyboard.SetTarget(dan, els2[e]);  
  103.                 Storyboard.SetTargetProperty(dan, new PropertyPath("(FrameworkElement.Height)"));  
  104.                 std2.Children.Add(dan);   
  105.             }   
  106.             this.Loaded += new RoutedEventHandler(Window1_Loaded);  
  107.         }   
  108.         void Window1_Loaded(object sender, RoutedEventArgs e)  
  109.         {  
  110.             MessageBox.Show("\n\n注意啊,别把眼睛靠得太近!!\n\n\n");  
  111.             std.Begin();  
  112.             std2.Begin();  
  113.         }  
  114.     }  
  115. }  


  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值