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

            DrawHyperbol drawHyperbol = new DrawHyperbol(bitmap);

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

            DrawHyperbol drawHyperbol = new DrawHyperbol(bitmap);

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