zoukankan      html  css  js  c++  java
  • 写了一个整人程序,较简单,有兴趣者可以看看

    程序是基于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(" 注意啊,别把眼睛靠得太近!! ");  
    111.             std.Begin();  
    112.             std2.Begin();  
    113.         }  
    114.     }  
    115. }  


      

  • 相关阅读:
    阿里巴巴微服务开源项目盘点(持续更新)
    云计算、大数据、编程语言学习指南下载,100+技术课程免费学!这份诚意满满的新年技术大礼包,你Get了吗?
    【机器学习PAI实战】—— 玩转人工智能之综述
    泡沫下的破浪者,智能语音产品到底落地何处?
    我们总结了每个技术团队都会遇到的 4 个难题
    在 Ali Kubernetes 系统中,我们这样实践混沌工程
    云上护航服务—保障云上的尖峰时刻
    本地 vs. 云:大数据厮杀的最终幸存者会是谁?— InfoQ专访阿里云智能通用计算平台负责人关涛
    WAF开放规则定义权:专家策略+用户自定义策略=Web安全
    队列的其本应用_迷官问题
  • 原文地址:https://www.cnblogs.com/xieweikai/p/6832812.html
Copyright © 2011-2022 走看看