コード例 #1
0
        private void button_draw_Click(object sender, EventArgs e)
        {
            if (!get_parabol())
            {
                return;
            }

            DrawParabol drawParapol = new DrawParabol(bitmap);

            if (comboBox_algo.Text.Equals("DDA"))
            {
                drawParapol.DDA(parabol, Color.Blue);
            }
            else if (comboBox_algo.Text.Equals("Bresenham"))
            {
                drawParapol.Bresenham(parabol, Color.Blue);
            }
            else if (comboBox_algo.Text.Equals("MidPoint"))
            {
                drawParapol.MidPoint(parabol, 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 parabol, or old one is not enough, create new one
            // otherwise, use the already have random list parabol
            if (parabolS.Count < this.numRand)
            {
                randParabolS(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();

            DrawParabol drawParabol = new DrawParabol(bitmap);

            if (comboBox_algo.Text.Equals("DDA"))
            {
                stopwatch.Restart();
                for (int i = 0; i < numRand; ++i)
                {
                    drawParabol.DDA(parabolS[i], Color.Blue);
                }
                stopwatch.Stop();
            }
            else if (comboBox_algo.Text.Equals("Bresenham"))
            {
                stopwatch.Restart();
                for (int i = 0; i < numRand; ++i)
                {
                    drawParabol.Bresenham(parabolS[i], Color.Blue);
                }
                stopwatch.Stop();
            }
            else if (comboBox_algo.Text.Equals("MidPoint"))
            {
                stopwatch.Restart();
                for (int i = 0; i < numRand; ++i)
                {
                    drawParabol.MidPoint(parabolS[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();
        }