Advertisement
Guest User

Untitled

a guest
Feb 16th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.17 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. using System.Windows.Media.Animation;
  16.  
  17. namespace WpfApplication41
  18. {
  19.     /// <summary>
  20.     /// Логика взаимодействия для MainWindow.xaml
  21.     /// </summary>
  22.     public partial class MainWindow : Window
  23.     {
  24.         public MainWindow()
  25.         {
  26.             InitializeComponent();
  27.         }
  28.         static double x, y;
  29.         static Random R = new Random();
  30.  
  31.         class body
  32.         {
  33.  
  34.             public body(Canvas canvas)
  35.             {
  36.                 Ellipse el = new Ellipse();
  37.                 Ellipse leg1, leg2;
  38.                 leg1 = new Ellipse();
  39.                 leg2 = new Ellipse();
  40.                 leg1.Width = 9;
  41.                 leg1.Height = 100;
  42.                 leg2.Width = 9;
  43.                 leg2.Height = 100;
  44.                 el.Width = 60;
  45.                 el.Height = 140;
  46.                 el.Fill = Brushes.Green;
  47.                 leg1.Fill = Brushes.Green;
  48.                 leg2.Fill = Brushes.Green;
  49.                 x = R.Next(0, 600);
  50.                 y = R.Next(0, 600);
  51.  
  52.                 RotateTransform a = new RotateTransform(0);
  53.                 el.RenderTransform = a;
  54.  
  55.                 Canvas.SetLeft(el, x);
  56.                 Canvas.SetTop(el, y);
  57.                 canvas.Children.Add(el);
  58.  
  59.                 Canvas.SetLeft(leg1, x - 40);
  60.                 Canvas.SetTop(leg1, y - 35);
  61.                 canvas.Children.Add(leg1);
  62.  
  63.                 Canvas.SetLeft(leg2, x - 20);
  64.                 Canvas.SetTop(leg2, y - 35);
  65.                 canvas.Children.Add(leg2);
  66.  
  67.  
  68.                 Storyboard st = new Storyboard();
  69.                 st.Duration = new Duration(TimeSpan.FromSeconds(1.0));
  70.                
  71.                 DoubleAnimation buttonAnimation = new DoubleAnimation()
  72.                 {
  73.                     From = 173, To = 203,
  74.                     Duration = st.Duration
  75.                 };
  76.  
  77.                // buttonAnimation.Duration = TimeSpan.FromSeconds(1);
  78.                 buttonAnimation.AutoReverse = true;
  79.                 buttonAnimation.RepeatBehavior = RepeatBehavior.Forever;
  80.                 PowerEase b = new PowerEase();
  81.                 b.Power = 2;
  82.                 b.EasingMode = EasingMode.EaseInOut;
  83.                 buttonAnimation.EasingFunction = b;
  84.                 el.RenderTransform.BeginAnimation(RotateTransform.AngleProperty, buttonAnimation);
  85.                 // el.BeginAnimation(Canvas.TopProperty, buttonAnimation);
  86.             }
  87.         }
  88.         class head
  89.         {
  90.             public head(Canvas canvas)
  91.             {
  92.                 Ellipse h = new Ellipse();
  93.                 Ellipse eye1, eye2;
  94.                 eye1 = new Ellipse();
  95.                 eye2 = new Ellipse();
  96.                 eye1.Width = 8;
  97.                 eye1.Height = 8;
  98.                 eye2.Width = 8;
  99.                 eye2.Height = 8;
  100.                 h.Width = 50;
  101.                 h.Height = 50;
  102.  
  103.                 h.Fill = Brushes.Green;
  104.                 eye1.Fill = Brushes.Black;
  105.                 eye2.Fill = Brushes.Black;
  106.                
  107.  
  108.                 RotateTransform a = new RotateTransform(0);
  109.                 h.RenderTransform = a;
  110.                 RotateTransform e1 = new RotateTransform(0);
  111.                 eye1.RenderTransform = e1;
  112.                 RotateTransform e2 = new RotateTransform(0);
  113.                 eye2.RenderTransform = e2;
  114.  
  115.  
  116.                
  117.  
  118.                 Canvas.SetLeft(h, x - 3);
  119.                 Canvas.SetTop(h, y - 125);
  120.                 canvas.Children.Add(h);
  121.  
  122.                 Canvas.SetLeft(eye1, x - 18);
  123.                 Canvas.SetTop(eye1, y - 155);
  124.                 canvas.Children.Add(eye1);
  125.  
  126.                 /* Canvas.SetLeft(h, x - 3);
  127.                  Canvas.SetTop(h, y - 125);
  128.                  canvas.Children.Add(h);*/
  129.  
  130.                 Storyboard st = new Storyboard();
  131.                 st.Duration = new Duration(TimeSpan.FromSeconds(1.0));
  132.  
  133.                 Storyboard ey1 = new Storyboard();
  134.                 ey1.Duration = new Duration(TimeSpan.FromSeconds(0.2));
  135.                
  136.  
  137.                 DoubleAnimation buttonAnimation = new DoubleAnimation()
  138.                 {
  139.                     From = 164,
  140.                     To = 266,
  141.                     Duration = st.Duration
  142.                 };
  143.  
  144.                 DoubleAnimation eye = new DoubleAnimation()
  145.                 {
  146.                     From = 296,
  147.                     To = 276,
  148.                     Duration = ey1.Duration
  149.                 };
  150.                 eye.AutoReverse = true;
  151.                 eye.RepeatBehavior = RepeatBehavior.Forever;
  152.                 PowerEase k = new PowerEase();
  153.                 k.Power = 2;
  154.                 k.EasingMode = EasingMode.EaseInOut;
  155.                 eye.EasingFunction = k;
  156.                 eye1.RenderTransform.BeginAnimation(RotateTransform.AngleProperty, eye);
  157.                 //eye1.RenderTransform.BeginAnimation(RotateTransform.CenterYProperty, eye);
  158.                // eye1.RenderTransform.BeginAnimation(RotateTransform.CenterXProperty, eye);
  159.  
  160.  
  161.                 // buttonAnimation.Duration = TimeSpan.FromSeconds(1);
  162.                 buttonAnimation.AutoReverse = true;
  163.                 buttonAnimation.RepeatBehavior = RepeatBehavior.Forever;
  164.                 PowerEase b = new PowerEase();
  165.                 b.Power = 2;
  166.                 b.EasingMode = EasingMode.EaseInOut;
  167.                 buttonAnimation.EasingFunction = b;
  168.                 h.RenderTransform.BeginAnimation(RotateTransform.AngleProperty, buttonAnimation);
  169.  
  170.                
  171.                 //eye1.RenderTransform.BeginAnimation(RotateTransform.AngleProperty, buttonAnimation);
  172.             }
  173.         }
  174.         class arms
  175.         {
  176.             public arms(Canvas canvas)
  177.             {
  178.                 Ellipse el = new Ellipse();
  179.                 el.Width = 85;
  180.                 el.Height = 9;
  181.                 Ellipse el1 = new Ellipse();
  182.                 el1.Width = 85;
  183.                 el1.Height = 9;
  184.                 el.Fill = Brushes.Green;
  185.                 el1.Fill = Brushes.Green;
  186.  
  187.                 RotateTransform a = new RotateTransform(170);
  188.                 el.RenderTransform = a;
  189.                 RotateTransform g = new RotateTransform(70);
  190.                 el1.RenderTransform = g;
  191.  
  192.                 Canvas.SetLeft(el, x - 24);
  193.                 Canvas.SetTop(el, y - 140);
  194.                 canvas.Children.Add(el);
  195.  
  196.                 Canvas.SetLeft(el1, x - 96);
  197.                 Canvas.SetTop(el1, y - 90);
  198.                 canvas.Children.Add(el1);
  199.  
  200.  
  201.                 Storyboard st = new Storyboard();
  202.                 st.Duration = new Duration(TimeSpan.FromSeconds(1.0));
  203.  
  204.                 DoubleAnimation buttonAnimation = new DoubleAnimation()
  205.                 {
  206.                     From = 358,
  207.                     To = 353,
  208.                     Duration = st.Duration
  209.                 };
  210.                 /*DoubleAnimation buttonAnimation2 = new DoubleAnimation()
  211.                 {
  212.                     From = 308,
  213.                     To = 330,
  214.                     Duration = st.Duration
  215.                 };*/
  216.  
  217.                 /* DoubleAnimation buttonAnimation2 = new DoubleAnimation()
  218.                  {
  219.                      From = 173,
  220.                      To = 203,
  221.                      Duration = st.Duration
  222.                  };*/
  223.  
  224.                 // buttonAnimation.Duration = TimeSpan.FromSeconds(1);
  225.                 buttonAnimation.AutoReverse = true;
  226.                 buttonAnimation.RepeatBehavior = RepeatBehavior.Forever;
  227.                 PowerEase b = new PowerEase();
  228.                 b.Power = 2;
  229.                 b.EasingMode = EasingMode.EaseInOut;
  230.                 buttonAnimation.EasingFunction = b;
  231.                 el.RenderTransform.BeginAnimation(RotateTransform.AngleProperty, buttonAnimation);
  232.                 el.RenderTransform.BeginAnimation(RotateTransform.CenterXProperty, buttonAnimation);
  233.  
  234.                 DoubleAnimation buttonAnimation2 = new DoubleAnimation()
  235.                 {
  236.                     From = 358,
  237.                     To = 343,
  238.                     Duration = st.Duration
  239.                 };
  240.  
  241.                 buttonAnimation2.AutoReverse = true;
  242.                 buttonAnimation2.RepeatBehavior = RepeatBehavior.Forever;
  243.                 PowerEase k = new PowerEase();
  244.                 k.Power = 2;
  245.                 k.EasingMode = EasingMode.EaseInOut;
  246.                 buttonAnimation2.EasingFunction = k;
  247.  
  248.                 el1.RenderTransform.BeginAnimation(RotateTransform.AngleProperty, buttonAnimation2);
  249.                 //el.RenderTransform.BeginAnimation(RotateTransform.CenterYProperty, buttonAnimation);
  250.             }
  251.         }
  252.         private void button_Click(object sender, RoutedEventArgs e)
  253.         {    
  254.             body b = new body(canvas);
  255.             arms a = new arms(canvas);
  256.             head h = new head(canvas);
  257.         }
  258.     }
  259. }
  260. /*
  261. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement