dhmt

Màu nền
Font chữ
Font size
Chiều cao dòng

        Graphics g;

        Pen p;

        Color c;

        Bitmap bmp;

        PointF[] poi;

        private void Form1_Load(object sender, EventArgs e)

        {

            g = this.CreateGraphics();

            p = new Pen(Color.Red, 4);

            c = Color.Green;

            bmp = new Bitmap(this.ClientSize.Width,this.ClientSize.Height);;

            poi = new PointF[4];

            poi[0] = new Point(50, 10);

            poi[1] = new Point(10, 10);

            poi[2] = new Point(10, 50);

            poi[3] = new Point(50, 50);

        }

        void myline(Bitmap bmp, PointF p1, PointF p2, Color c)

        {

            Graphics bg = Graphics.FromImage(bmp);

            p1.Y = bmp.Height - p1.Y;

            p2.Y = bmp.Height - p2.Y;

            bg.DrawLine(new Pen(c), p1.X, p1.Y, p2.X, p2.Y);

        }

       void vedagiac(Bitmap bmp, PointF[] poi, Color c)

        {

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

                myline(bmp, poi[i], poi[i + 1], c);

            myline(bmp, poi[0], poi[poi.Length - 1], c);

        }

 PointF quay(PointF poi, double x)

        {

            PointF Q = new PointF();

            x = x * Math.PI / 180;

            Q.X = poi.X * (float)Math.Cos(x) - poi.Y * (float)Math.Sin(x);

            Q.Y = poi.X * (float)Math.Sin(x) + poi.Y * (float)Math.Cos(x);

            return Q;

        }

        PointF[] quaydagiac(PointF[] poi, double x)

        {

            PointF[] Q = new PointF[poi.Length];

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

                Q[i] = quay(poi[i], x);

            return Q;

        }

        private void Form1_Paint(object sender, PaintEventArgs e)

        {

            vedagiac(bmp, poi, Color.Black);

            poi = tinhtiendagiac(poi, 50, 30);

            vedagiac(bmp, poi, Color.Red);

            poi = phongtodagiac(poi, 2, 3);

            vedagiac(bmp, poi, Color.Brown);

            poi = biendangdagiac(poi, 2);

            vedagiac(bmp, poi, Color.Chocolate);

            poi = quaydagiac(poi, 20);

            vedagiac(bmp, poi, Color.Crimson);

            g.DrawImage(bmp, 0, 0);

        }

void Tobien(int x,int y,Bitmap bmp, Color mto, Color mbien)

        {

            Color m = bmp.GetPixel(x, y);

            if (!trungmau(m, mto) && !trungmau(m, mbien))

            {

                bmp.SetPixel(x, y, mto);

                Tobien(x - 1, y, bmp, mto, mbien);

                Tobien(x, y + 1, bmp, mto, mbien);

                Tobien(x + 1, y, bmp, mto, mbien);

                Tobien(x, y - 1, bmp, mto, mbien);

            }

        }

        Boolean trungmau(Color c1, Color c2)

        {

            return (c1.A == c2.A && c1.R == c2.R && c1.B == c2.B && c1.G == c2.G);

        }

Tobien(100,bmp.Height-75, bmp, Color.Blue, Color.Black);

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