Ejemplo n.º 1
0
        private void button_drawLine_Click(object sender, EventArgs e)
        {
            // get location of point 1, point 2
            if (!get_p1p2())
            {
                return;
            }

            DrawLine drawLine = new DrawLine(bitmap);

            if (comboBox_algo.Text.Equals("DDA"))
            {
                drawLine.DDA(line, Color.Blue);
            }
            else if (comboBox_algo.Text.Equals("Bresenham"))
            {
                drawLine.Bresenham(line, Color.Blue);
            }
            else if (comboBox_algo.Text.Equals("MidPoint"))
            {
                drawLine.MidPoint(line, Color.Blue);
            }
            else if (comboBox_algo.Text.Equals("Xiaolin Wu"))
            {
                drawLine.XiaolinWu(line, Color.Blue);
            }

            // refresh picture box every draw
            pictureBox_draw.Refresh();
        }
Ejemplo n.º 2
0
        private void button_rand_click(object sender, EventArgs e)
        {
            if (!get_numRand())
            {
                return;
            }

            // clear all drawings before random
            clearAll();

            // if no random list line, or old one is not enough, create new one
            // otherwise, use the already have random list line
            if (lineS.Count < this.numRand)
            {
                randLineS(numRand);
            }

            // StopWatch object for calculating execution time of the algorithm
            // StartNew and Stop for make sure stopwatch is not redundant object
            Stopwatch stopwatch = Stopwatch.StartNew();

            stopwatch.Stop();

            DrawLine drawLine2D = new DrawLine(bitmap);

            if (comboBox_algo.Text.Equals("DDA"))
            {
                stopwatch.Restart();
                for (int i = 0; i < numRand; ++i)
                {
                    drawLine2D.DDA(lineS[i], Color.Blue);
                }
                stopwatch.Stop();
            }
            else if (comboBox_algo.Text.Equals("Bresenham"))
            {
                stopwatch.Restart();
                for (int i = 0; i < numRand; ++i)
                {
                    drawLine2D.Bresenham(lineS[i], Color.Blue);
                }
                stopwatch.Stop();
            }
            else if (comboBox_algo.Text.Equals("MidPoint"))
            {
                stopwatch.Restart();
                for (int i = 0; i < numRand; ++i)
                {
                    drawLine2D.MidPoint(lineS[i], Color.Blue);
                }
                stopwatch.Stop();
            }
            else if (comboBox_algo.Text.Equals("Xiaolin Wu"))
            {
                stopwatch.Restart();
                for (int i = 0; i < numRand; ++i)
                {
                    drawLine2D.XiaolinWu(lineS[i], Color.Blue);
                }
                stopwatch.Stop();
            }

            // set running time to text box
            textBox_randLineTime.Text = stopwatch.ElapsedMilliseconds.ToString() + " ms";

            // refresh picture box every draw
            pictureBox_draw.Refresh();
        }