zoukankan      html  css  js  c++  java
  • [Silverlight 2.0 控制物体绕圆弧运行(C#初探篇)]

    我自己写的第一个 Silverlight 2.0 程序 

     
    [Silverlight 2.0 控制物体绕圆弧运行(C#初探篇)] 
               
    程序运行时:小地球将绕着圆形轨迹做圆周运动。 

    xaml】:很简单,一张图片,再使用一个 Ellipse ,无填充颜色即可,记得为图片起名字 [earth] 
    <Canvas Margin="0,0,0,0"> 
      <Ellipse Height="300" Width="300" Canvas.Left="0" Canvas.Top="0" Fill="{x:Null}" 

               Stroke="#FFFFA500" StrokeThickness="3"/> 
      <Image Height="50" Width="50" Canvas.Left="0" Canvas.Top="0" Source="52.png" x:Name="earth"/> 
    </Canvas>
     
    xaml.cs记得引用时间控件的命名空间 
    using System.Windows.Threading; 
    public partial class Page : UserControl 
        { 
            DispatcherTimer timer1 = new DispatcherTimer(); 
            DispatcherTimer timer2 = new DispatcherTimer
    (); 
        //设置 x 坐标轴变化范围(300 为该圆的直径) 
            double x_temp = 0; 
            double x2_temp = 300; 
            //初始加载事件 
            public Page() 
            { 
                InitializeComponent(); 
                //设置时钟频率为 5 毫秒 
                TimeSpan ts = TimeSpan.FromMilliseconds(0.005); 
                timer1.Interval = ts; 
                timer1.Tick += new EventHandler(timer_Tick); 
                timer1.Start(); 
                timer2.Interval = ts; 
                timer2.Tick += new EventHandler(timer2_Tick); 
            } 
            /// <summary> 
            /// 根据圆弧的 x 坐标获取 y 坐标的方法 
            /// </summary> 
            /// <param name="a">圆弧中心点的 x 坐标</param> 
            /// <param name="b">圆弧中心点的 y 坐标</param> 
            /// <param name="c">圆弧的半径</param> 
            /// <param name="d">x 坐标轴的最大范围</param> 
            /// <returns>返回与 x 坐标相关的圆弧 y 坐标</returns>
     
            public double get_y(double a, double b, double c, double d) 
            { 
                double A = a; 
                double B = b; 
                double R = c; 
                double x = d; 
                double y = 0; 
                //分解 (x - a)(x - a) 
                double x_result = (x * x) - (2 * A * x) + (A * A); 
               //变换圆标准方程式 
                for (x = 0; x <= 2 * R;x++ ) 
                { 
                    double j = Math.Sqrt(R * R - x_result); 
                    y = j + B; 
                } 
                return y; 
            } 
            /// <summary> 
            /// timer2 控制事件 
            /// 该事件处控制一个 圆心为 150,150,半径为 150 的圆弧(下半弧) 
            /// </summary>
     
            void timer2_Tick(object sender, EventArgs e) 
            { 
                double y2_temp = this.get_y(150,150,150,x2_temp); 
                earth.SetValue(Canvas.LeftProperty,x2_temp-25); 
                earth.SetValue(Canvas.TopProperty,y2_temp-25); 
                x2_temp--; 
                //当 x 坐标递减到等于 0 时,下半弧完成,重新初始 
                if (x2_temp == 0) 
                { 
                    timer2.Stop(); 
                    timer1.Start(); 
                    x2_temp = 300; 
                } 
            } 
            /// <summary> 
            /// timer1 控制事件 
            /// 该事件处控制一个 圆心为 150,150,半径为 150 的圆弧(上半弧) 
            /// </summary>
     
            void timer_Tick(object sender, EventArgs e) 
            { 
                x_temp = x_temp + 1; 
                double y_temp = this.get_y(150, 150, 150, x_temp); 
                //上半弧的纵坐标等于圆弧的直径减去下半弧的纵坐标 
                double y_really = 300 - y_temp; 
                earth.SetValue(Canvas.LeftProperty, x_temp-25); 
                earth.SetValue(Canvas.TopProperty, y_really-25); 
                //当 x 坐标递增到等于圆弧直径长时,上半弧完成,重新初始 
                if (x_temp == 300) 
                { 
                    timer1.Stop(); 
                    timer2.Start(); 
                    x_temp = 0; 
                } 
            } 
        }
     


  • 相关阅读:
    Security headers quick reference Learn more about headers that can keep your site safe and quickly look up the most important details.
    Missing dollar riddle
    Where Did the Other Dollar Go, Jeff?
    proteus 与 keil 联调
    cisco router nat
    router dhcp and dns listen
    配置802.1x在交换机的端口验证设置
    ASAv931安装&初始化及ASDM管理
    S5700与Cisco ACS做802.1x认证
    playwright
  • 原文地址:https://www.cnblogs.com/meimao5211/p/3428027.html
Copyright © 2011-2022 走看看