Bai_3_Chuong2

namespace Bai_3_Chuong2

{

    public partial class Bai_3_Chuong2 : Form

    {

        Bitmap b;

        Graphics g;

        Pen color;

        Color backcolor;

        public Bai_3_Chuong2()

        {

            InitializeComponent();

            Rectangle r = this.ClientRectangle;

            color = new Pen(Color.Red);

            b=new Bitmap(r.Width , r.Height );

            g=Graphics.FromImage(b) ;

            backcolor = this.BackColor;

            g.Clear(backcolor);

        }

        bool CungMau(Color a, Color b)

        {

            if (a.R == b.R && a.G == b.G && a.B == b.B)

                return true;

            return false;

        }

        void fillrescuse(Point s, Color fc, Color bc)

        {

            Stack<Point> stack = new Stack<Point>();

            stack.Push(s);

            while (stack.Count != 0)

            {

                s = stack.Pop();

                Color cc = b.GetPixel(s.X, s.Y);

                if (!CungMau(cc, bc))

                {

                    b.SetPixel(s.X, s.Y, fc);

                    Point pl = new Point(s.X - 1, s.Y);

                    Point pr = new Point(s.X + 1, s.Y);

                    Point pt = new Point(s.X, s.Y - 1);

                    Point pb = new Point(s.X, s.Y + 1);

                    stack.Push(pl); stack.Push(pr);

                    stack.Push(pt); stack.Push(pb);

                }

            }

        }

        public void DrawPolyGon(Point[]p)

        {

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

            {

                g.DrawLine(new Pen(Color.Red), p[i], p[i + 1]);

                g.DrawLine(new Pen(Color.Red), p[p.Length - 1], p[0]);

            }

        }

        void DDA(int xa, int ya, int xb, int yb)

        {

        }

        private void Bai_3_Chuong2_Load(object sender, EventArgs e)

        {

        }

        private void Bai_3_Chuong2_Paint(object sender, PaintEventArgs e)

        {

            Point[] p = { new Point(10,10), new Point(200, 200), new Point(200, 60) };

                DrawPolyGon(p);

                fillrescuse(new Point(50, 30), Color.Red, Color.Red);

            Graphics gr = e.Graphics;

            gr.DrawImageUnscaled(b, 0, 0);

        }

Bạn đang đọc truyện trên: AzTruyen.Top

Tags: