欢迎光临
我们一直在努力

Rotation Sample-.NET教程,Windows开发

建站超值云服务器,限时71元/月
rotation sample
submitted by user level date of submission
john o扗onnell intermediate 04/24/2001

download exe: rotationsamplej.zip 6 kb
description of the article
after reading mike golds article on transforms i thought i would get things moving a bit!
overriding the onpaint method and using the timer class allows us to create a simple animation where we rotate a line around a central point.
anyone want to create an asteroids clone in c#? j
  
source code:

using system;
using system.drawing;
using system.collections;
using system.componentmodel;
using system.windows.forms;
using system.data;
using system.drawing.drawing2d;
namespace rotationb2
{
      /// <summary>
      /// summary description for form1.
      /// </summary>
      public class form1 : system.windows.forms.form
      {
            private system.windows.forms.timer timer1;
            private system.componentmodel.icontainer components;
            public float f=0;
            public form1()
            {
                  //
                  // required for windows form designer support
                  //
                  initializecomponent();
                  //
                  // todo: add any constructor code after initializecomponent
call
                //
            }
            /// <summary>
            /// clean up any resources being used.
            /// </summary>
            protected override void dispose( bool disposing )
            {
                  if( disposing )
                  {
                        if (components != null)
                        {
                              components.dispose();
                        }
                  }
                  base.dispose( disposing );
            }
  
            #region windows form designer generated code
            /// <summary>
            /// required method for designer support – do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void initializecomponent()
            {
                  this.components = new system.componentmodel.container();
                  this.timer1 = new system.windows.forms.timer(this.components);
                  //
                  // timer1
                  //
                  this.timer1.enabled = true;
                  this.timer1.interval = 50;
                  this.timer1.tick += new system.eventhandler(this.timer1_tick);
                  //
                  // form1
                  //
                  this.autoscalebasesize = new system.drawing.size(5, 13);
                  this.clientsize = new system.drawing.size(240, 221);
                  this.name = "form1";
                  this.text = "rotationb2";
             }
            #endregion
             /// <summary>
            /// the main entry point for the application.
            /// </summary>
            [stathread]
            static void main ()
            {
                  application.run(new form1());
            }

            protected override void onpaint(painteventargs e)
            {
                  e.graphics.drawellipse(pens.red,0,0,220,220);
                  graphicspath gp = new graphicspath();
                  gp.addline(30,30,110,110);
                  matrix rotationtransform = new matrix(1,0, 0,1,1,1);  //
rotation matrix
                  pointf therotationpoint = new pointf(110.0f, 110.0f);  //
rotation point
                  rotationtransform.rotateat(f, therotationpoint);
                  gp.transform(rotationtransform);
                  e.graphics.drawpath(pens.blue, gp);
                  f=f+10;
                  if (f==360)
                  f=0;              
            }
             private void timer1_tick(object sender, system.eventargs e)
            {
                  //force client window to be refreshed
                  this.refresh();
            }
      }
}

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » Rotation Sample-.NET教程,Windows开发
分享到: 更多 (0)