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... ♥

VeXeHoi

namespace VeXeHoi

{

    public partial class Form1 : Form

    {

        Graphics g;

        Bitmap b;

        Pen pen;

        point2D[] vert;

        Color bk;

        public struct point2D

        {

            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 Tinhtiendiem(ref double x, ref double y, double tx, double ty)

        {

            x += tx;

            y += ty;

        }

        public void TinhtienDsdiem(point2D[] p, double tx, double ty)

        {//tu viet

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

            {

                Tinhtiendiem(ref p[i].x, ref p[i].y, tx, ty);

            }

        }

        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]);

        }

        private void Form1_Load(object sender, EventArgs e)

        {

            vert = new point2D[6];

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

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

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

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

            vert[4].x = 200; vert[4].y = 200;

            drawpolygon(vert);

            g.DrawEllipse(pen, 120, b.Height - 100, 30, 30);

            g.DrawEllipse(pen, 190, b.Height - 100, 30, 30);

            drawpolygon(vert);

        }

        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);

            TinhtienDsdiem(vert,10,0);

            drawpolygon(vert);

            g.DrawEllipse(pen, 120, b.Height - 100, 30, 30);

            g.DrawEllipse(pen, 190, b.Height - 100, 30, 30);

            this.Invalidate();

        }

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

Tags: