Chào các bạn! Vì nhiều lý do từ nay Truyen2U chính thức đổi tên là Truyen247.Pro. Mong các bạn tiếp tục ủng hộ truy cập tên miền mới này nhé! Mãi yêu... ♥

VeTamGiac

namespace VeTamGiac

{

    public partial class Form1 : Form

    {

        Graphics g;

        Bitmap b;

        Pen pen;

        Color bk;

        point2D[] vert;

        bool start;

        public struct point2D// tao diem

        {

            public double x, y;

        }

        public Form1()

        {           

            InitializeComponent();

            b = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height);

            g = Graphics.FromImage(b);

            pen = new Pen(Color.Black);

            this.bk = this.BackColor;

            this.g.Clear(this.bk);

            timer1.Enabled = true;

            timer1.Start();

        }

        public void myline(point2D p1, point2D p2)

        {

            double y1 = b.Height - p1.y;//doi toa do

            double y2 = b.Height - p2.y;//chuyen ve toa do duoi goc trai

            g.DrawLine(pen, (float)p1.x, (float)y1, (float)p2.x, (float)y2);

        }

        public void drawpolygon(point2D[] p)

        {

            for (int i = 0; i < p.Length - 1; i++)

            {

                myline(p[i], p[i + 1]);

            }

            myline(p[p.Length - 1], p[0]);

        }

        public void xoaydiem(ref double x, ref double y, double alpha)

        {

            alpha = Math.PI * alpha / 180;

            double x1 = Math.Cos(alpha) * x - Math.Sin(alpha) * y;//cong them 1 phan nua neu xoay theo tam c

            double y1 = Math.Sin(alpha) * x + Math.Cos(alpha) * y;

            x = x1; y = y1;

        }

        public void xoaydiemtoadobatky(ref double x, ref double y, double alpha, double incx, double incy)

        {

            alpha = Math.PI * alpha / 180;

            double x1 = Math.Cos(alpha) * x - Math.Sin(alpha) * y + (1 - Math.Cos(alpha)) * incx + Math.Sin(alpha) * incy;//cong them 1 phan nua neu xoay theo tam c

            double y1 = Math.Sin(alpha) * x + Math.Cos(alpha) * y - Math.Sin(alpha) * incx + (1 - Math.Cos(alpha)) * incy;

            x = x1; y = y1;

        }

        public void xoayDsdiemtoadobaky(point2D[] p, double al, double incx, double incy)

        {

            for (int i = 0; i < p.Length; i++)

            {

                xoaydiemtoadobatky(ref p[i].x, ref p[i].y, al, incx, incy);

            }

        }

        private void Form1_Load(object sender, EventArgs e)

        {

            vert = new point2D[3];

            vert[0].x = 100; vert[0].y = 100;

            vert[1].x = 200; vert[1].y = 100;

            vert[2].x = 150; vert[2].y = 200;

        }

        private void Form1_Paint(object sender, PaintEventArgs e)

        {

            drawpolygon(vert);

            Graphics gr = e.Graphics;

            gr.DrawImageUnscaled(b, 0, 0);

        }

        private void timer1_Tick(object sender, EventArgs e)

        {

            g.Clear(bk);

            xoayDsdiemtoadobaky(vert, 10, vert[0].x, vert[0].y);

            drawpolygon(vert);

            this.Invalidate();

        }

        private void Form1_KeyPress(object sender, KeyPressEventArgs e)

        {

            if (!start)

            {

                start = true;

                timer1.Stop();

            }

            else

            {

                start = false;

                timer1.Start();

            }

Bạn đang đọc truyện trên: Truyen247.Pro

Tags: