Exemplo n.º 1
0
        private void cmd_clear_Click(object sender, EventArgs e)
        {
            points.Clear(); // clear input points
            polygon = null;
            m       = null; // clear shape
            listBox1.Items.Clear();
            cmb_minumum.Items.Clear();
            cmb_other.Items.Clear();
            Graphics g = panel_screen.CreateGraphics();

            g.Clear(Color.White);
            cmd_3color.Enabled  = false;
            cmd_animate.Enabled = false;
            cmd_cut.Enabled     = false;
            cmd_scan1.Enabled   = false;
            cmd_scan2.Enabled   = false;
            button5.Text        = "-";
            button6.Text        = "-";
            button7.Text        = "-";
            button5.Enabled     = false;
            button6.Enabled     = false;
            button7.Enabled     = false;
            label1.Visible      = false;
            status = prosess_status.WAITING_USER_INPUT;
        }
Exemplo n.º 2
0
        private void panel_screen_MouseUp(object sender, MouseEventArgs e)
        {
            // fires when mouse button is released after click

            if (e.Button == MouseButtons.Left) // if left-click
            {
                // we're getting point input from user
                Point p = new Point(e.X, e.Y);
                points.Add(p);
                status = prosess_status.DRAWING;
            }
            else if (e.Button == MouseButtons.Right) // right-click
            {
                if (points.Count < 3)                // polygon needs at least 3 points
                {
                    MessageBox.Show("You have to click at least 3 points!");
                    return;
                }
                // construct the polygon from entered points
                polygon = new Point[points.Count];
                for (int i = 0; i < points.Count; i++)
                {
                    polygon[i] = (Point)points[i];
                }

                Graphics g = panel_screen.CreateGraphics();
                g.Clear(Color.White); // clear background
                //Szin
                draw_polygon();       // draw the polygon

                status          = prosess_status.POLYGON_READY;
                cmd_cut.Enabled = true; // enable the triangulate button
            }
        }
Exemplo n.º 3
0
        // triangulate button
        private void cmd_cut_Click(object sender, EventArgs e)
        {
            // if there's not a complete polygon yet
            if (polygon == null | status != prosess_status.POLYGON_READY)
            {
                return; // cancel prosessing
            }
            if (polygon.Length < 3)
            {
                return;
            }

            m = new mPolygonShape(polygon);             // initialize a new polygon-shape
            m.triangulate();                            // triangualete
            m.lb = listBox1;                            // assign reference of listbox
            listBox1.Items.Clear();                     // clear listbox

            Graphics g = panel_screen.CreateGraphics(); // Graphics handle

            g.Clear(Color.White);                       // cls screen

            // draw the result
            draw_ears(false); // wire_frame_only=false, allows filling of polygons
            draw_polygon();   // top of it, draw polygon, vertex markers
            status             = prosess_status.TRIANGULATION_COMPLETED;
            cmd_3color.Enabled = true;
        }
Exemplo n.º 4
0
        private void button9_Click(object sender, EventArgs e)
        {
            // we're getting point input from user

            Point p = new Point(226, 88);

            points.Add(p);

            Point a = new Point(180, 150);

            points.Add(a);

            Point b = new Point(111, 104);

            points.Add(b);

            Point c = new Point(65, 201);

            points.Add(c);

            Point d = new Point(101, 276);

            points.Add(d);

            Point r = new Point(219, 328);

            points.Add(r);

            Point t = new Point(317, 303);

            points.Add(t);
            Point z = new Point(373, 241);

            points.Add(z);
            Point x = new Point(259, 220);

            points.Add(x);
            Point m = new Point(321, 130);

            points.Add(m);
            status = prosess_status.DRAWING;


            polygon = new Point[points.Count];
            for (int i = 0; i < points.Count; i++)
            {
                polygon[i] = (Point)points[i];
            }

            Graphics g = panel_screen.CreateGraphics();

            g.Clear(Color.White); // clear background
                                  //Szin
            draw_polygon();       // draw the polygon

            status          = prosess_status.POLYGON_READY;
            cmd_cut.Enabled = true; // enable the triangulate button
        }
Exemplo n.º 5
0
        // animate the 3-coloring
        private void cmd_animate_Click(object sender, EventArgs e)
        {
            status     = prosess_status.ANIMATING;
            m.animated = new Boolean[m.input_vertices.Length]; // animation construct

            for (int i = 0; i < m.animated.Length; i++)
            {
                m.animated[i] = false; // none of guards shown yet
            }

            for (int i = 0; i < listBox1.Items.Count; i++) // loop through listbox
            {
                listBox1.SelectedIndex = i;                // let listbox select the item and show
                if (i != listBox1.Items.Count - 1)
                {
                    Application.DoEvents();
                    Thread.Sleep(750);      // wait 750 ms for next animation step
                }
            }

            Graphics g = panel_screen.CreateGraphics();

            g.Clear(Color.White);
            draw_polygon();   // draw markers
            draw_ears(false); // draw wireframe-only triangles
            draw_3colors();

            label1.Text    = "Minumul de paznici: " + m.count_colors(m.get_minumum_color()).ToString(); // minimum color count
            label1.Visible = true;

            button5.Text    = (cmb_minumum.Items[cmb_minumum.SelectedIndex].ToString());
            button5.Enabled = true;

            if (cmb_other.Items.Count == 1)
            {
                button6.Text    = cmb_other.Items[cmb_other.SelectedIndex].ToString();
                button6.Enabled = true;
            }
            if (cmb_other.Items.Count == 2)
            {
                button6.Text = cmb_other.Items[cmb_other.SelectedIndex].ToString();
                button7.Text = cmb_other.Items[cmb_other.SelectedIndex + 1].ToString();

                button6.Enabled = true;
                button7.Enabled = true;
            }

            status = prosess_status.TRICOLOR_COMPLETED;
        }
Exemplo n.º 6
0
        private void cmd_clear_Click(object sender, EventArgs e)
        {
            points.Clear(); // clear input points
            polygon = null;
            m       = null; // clear shape
            listBox1.Items.Clear();
            cmb_minumum.Items.Clear();
            cmb_other.Items.Clear();
            Graphics g = panel_screen.CreateGraphics();

            g.Clear(Color.CornflowerBlue);
            cmd_3color.Enabled  = false;
            cmd_animate.Enabled = false;
            cmd_cut.Enabled     = false;
            cmd_scan1.Enabled   = false;
            cmd_scan2.Enabled   = false;
            status = prosess_status.WAITING_USER_INPUT;
        }
Exemplo n.º 7
0
        // 3-color the polygons
        private void cmd_3color_Click(object sender, EventArgs e)
        {
            // if triangulation is complete
            if ((m != null) && (status == prosess_status.TRIANGULATION_COMPLETED))
            {
                m.traverse(); // start 3-coloring the graph
                Graphics g = panel_screen.CreateGraphics();
                g.Clear(Color.CornflowerBlue);
                draw_polygon();   // draw markers
                draw_ears(false); // draw wireframe-only triangles
                draw_3colors();   // draw 3-coloring

                // process minumu-guards
                cmb_minumum.Items.Add(m.str_color(m.get_minumum_color()));                                         // find minimum-color
                cmb_minumum.SelectedIndex = 0;
                lbl_min_guards.Text       = "Minumum Guards: " + m.count_colors(m.get_minumum_color()).ToString(); // minimum color count

                // process others
                for (int i = 1; i <= 3; i++)
                {
                    if ((vertex_color)i != m.get_minumum_color())
                    {
                        if (m.count_colors((vertex_color)i) == m.count_colors(m.get_minumum_color()))
                        {
                            cmb_minumum.Items.Add(m.str_color((vertex_color)i));
                        }
                        else
                        {
                            cmb_other.Items.Add(m.str_color((vertex_color)i));
                        }
                    }
                }
                if (cmb_other.Items.Count > 0)
                {
                    cmb_other.SelectedIndex = 0;
                }

                status = prosess_status.TRICOLOR_COMPLETED;
                cmd_animate.Enabled = true;
                cmd_scan1.Enabled   = true;
                cmd_scan2.Enabled   = true;
            }
        }
Exemplo n.º 8
0
        // animate the 3-coloring
        private void cmd_animate_Click(object sender, EventArgs e)
        {
            status     = prosess_status.ANIMATING;
            m.animated = new Boolean[m.input_vertices.Length]; // animation construct

            for (int i = 0; i < m.animated.Length; i++)
            {
                m.animated[i] = false; // none of guards shown yet
            }

            for (int i = 0; i < listBox1.Items.Count; i++) // loop through listbox
            {
                listBox1.SelectedIndex = i;                // let listbox select the item and show
                if (i != listBox1.Items.Count - 1)
                {
                    Application.DoEvents();
                    Thread.Sleep(750);      // wait 750 ms for next animation step
                }
            }
            status = prosess_status.TRICOLOR_COMPLETED;
        }
Exemplo n.º 9
0
 public Form1()
 {
     status = prosess_status.WAITING_USER_INPUT;
     InitializeComponent(); // init window components
 }
Exemplo n.º 10
0
        // scans selected guards vision
        private void scan_colors(vertex_color c)
        {
            Point    p;
            Graphics g = panel_screen.CreateGraphics();
            Brush    b = Brushes.White;

            // set guard colors
            switch (c)
            {
            case vertex_color.Empty:
                break;

            case vertex_color.Red:
                b = Brushes.Red;    //Itt  Firebrick
                break;

            case vertex_color.Green:
                b = Brushes.Lime;    //Itt DarkGreen
                break;

            case vertex_color.Blue:
                b = Brushes.Blue;    //Itt RoyalBlue
                break;

            default:
                break;
            }

            g.Clear(Color.White);
            status = prosess_status.ANIMATING;

            draw_ears(true);                                 // draw tringulated polygon - wireframe-only mode

            for (int i = 0; i < m.vertex_colors.Length; i++) // loop through guards
            {
                if (m.vertex_colors[i] == c)                 // if this is the guard we'r looking for
                {
                    p = m.input_vertices[i];                 // get guard point
                    Rectangle r = new Rectangle(p.X - 10, p.Y - 10, 20, 20);
                    g.FillEllipse(b, r);                     // draw guard
                    g.DrawEllipse(new Pen(Color.White, 1), r);
                    Application.DoEvents();
                    Thread.Sleep(750);                                                                     // wait 750 ms for next step

                    for (int j = 0; j < m.polygons.Length; j++)                                            // loop through polygons and find related polygons to current point
                    {
                        if ((p == m.polygons[j][0]) || (p == m.polygons[j][1]) || (p == m.polygons[j][2])) // if related polygon
                        {
                            g.FillPolygon(b, m.polygons[j]);                                               // draw the polygon
                            g.DrawPolygon(Pens.White, m.polygons[j]);
                            Application.DoEvents();
                            Thread.Sleep(750); // wait 750 ms for next step
                        }
                    }
                    g.FillEllipse(b, r);
                    g.DrawEllipse(new Pen(Color.White, 1), r);
                }
            }

            status = prosess_status.TRICOLOR_COMPLETED;
        }