예제 #1
0
        private void button_draw_Click(object sender, EventArgs e)
        {
            if (!get_ellipse())
            {
                return;
            }

            DrawEllipse drawEllipse = new DrawEllipse(bitmap);

            if (comboBox_algo.Text.Equals("DDA"))
            {
                drawEllipse.DDA(ellipse, Color.Blue);
            }
            else if (comboBox_algo.Text.Equals("Bresenham"))
            {
                drawEllipse.Bresenham(ellipse, Color.Blue);
            }
            else if (comboBox_algo.Text.Equals("MidPoint"))
            {
                drawEllipse.MidPoint(ellipse, Color.Blue);
            }

            // refresh picture box every draw
            pictureBox_draw.Refresh();
        }
예제 #2
0
        private void button_randDraw_Click(object sender, EventArgs e)
        {
            if (!get_randNum())
            {
                return;
            }

            // clear all drawings before random
            clearAll();

            // if no random list ellipse, or old one is not enough, create new one
            // otherwise, use the already have random list ellipse
            if (ellipseS.Count < this.numRand)
            {
                randEllipseS(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();

            DrawEllipse drawEllipse = new DrawEllipse(bitmap);

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

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

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