예제 #1
0
        /// <summary>
        /// for calling triangle class
        /// </summary>
        /// <param name="rBase">variable for base of the triangle</param>
        /// <param name="adj">variable for adjacent of the triangle</param>
        /// <param name="hyp"></param>
        private void DrawTriangle(int rBase, int adj, int hyp)
        {
            gap = Panel_Draw.CreateGraphics();
            gap.RotateTransform(rotation);//for rotating the shape
            _s1 = Xaxis;
            _s2 = Yaxis;

            _s3 = rBase;
            _s4 = adj;
            _s5 = hyp;


            xi1 = _s1;
            yi1 = _s2;
            xi2 = Math.Abs(_s3);
            yi2 = _s2;

            xii1 = _s1;
            yii1 = _s2;
            xii2 = _s1;
            yii2 = Math.Abs(_s4);

            xiii1 = Math.Abs(_s3);
            yiii1 = _s2;
            xiii2 = _s1;
            yiii2 = Math.Abs(_s4);

            ShapeFactory shapeFactory = new ShapeFactory();
            Shape        c            = shapeFactory.GetShape("triangle");

            c.set(fill, pcolor, xi1, yi1, xi2, yi2, xii1, yii1, xii2, yii2, xiii1, yiii1, xiii2, yiii2);
            c.Draw(gap);
        }
예제 #2
0
        /// <summary>
        /// method for calling circle class
        /// </summary>
        /// <param name="radius">value from the user</param>
        private void DrawCircle(int radius)
        {
            //-----------------------------
            gap = Panel_Draw.CreateGraphics();
            _s1 = Xaxis;
            _s2 = Yaxis;
            _s3 = radius;
            ShapeFactory shapeFactory = new ShapeFactory();
            Shape        c            = shapeFactory.GetShape("circle");

            c.set(fill, pcolor, _s1, _s2, _s3 * 2, _s3 * 2);
            //c.draw(set);
            c.Draw(gap);
        }
예제 #3
0
        /// <summary>
        /// Method for calling rectangle class
        /// </summary>
        /// <param name="width">getting width of the </param>
        /// <param name="height"></param>


        /// <summary>
        /// Method for calling rectangle class
        /// </summary>
        /// <param name="width">getting width of the </param>
        /// <param name="height"></param>
        private void DrawSquare(int side, int side1)
        {
            gap = Panel_Draw.CreateGraphics();
            gap.RotateTransform(rotation);//for rotating the shape
            _s1 = Xaxis;
            _s2 = Yaxis;
            _s3 = side;
            _s4 = side1;
            //_size4 = side;
            ShapeFactory shapeFactory = new ShapeFactory();
            Shape        c            = shapeFactory.GetShape("square");

            c.set(fill, pcolor, _s1, _s2, _s3, _s4);
            c.Draw(gap);
        }
예제 #4
0
        /// <summary>
        /// Method for calling rectangle class
        /// </summary>
        /// <param name="width">getting width of the </param>
        /// <param name="height"></param>
        private void DrawRectangle(int width, int height)
        {
            gap = Panel_Draw.CreateGraphics();
            gap.RotateTransform(rotation);//for rotating the shape
            _s1 = Xaxis;
            _s2 = Yaxis;
            _s3 = width;
            _s4 = height;



            ShapeFactory shapeFactory = new ShapeFactory();
            Shape        c            = shapeFactory.GetShape("rectangle");

            c.set(fill, pcolor, _s1, _s2, _s3, _s4);
            c.Draw(gap);
        }
예제 #5
0
 /// <summary>
 /// this is the constructor
 /// </summary>
 public Form1()
 {
     InitializeComponent();
     gap = Panel_Draw.CreateGraphics();
 }
예제 #6
0
        int fill     = 0;//this is for the fill on and off option


        /// <summary>
        /// all logic to run command in commnad line
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_run_Click(object sender, EventArgs e)
        {
            Regex regexRun   = new Regex(@"run");
            Regex regexClear = new Regex(@"clear");
            Regex regexReset = new Regex(@"reset");
            Regex regexMT    = new Regex(@"moveto (.*[\d])([,])(.*[\d])");
            Regex regexDT    = new Regex(@"drawto (.*[\d])([,])(.*[\d])");

            Regex regexR = new Regex(@"rectangle (.*[\d])([,])(.*[\d])");
            Regex regexC = new Regex(@"circle (.*[\d])");
            Regex regexT = new Regex(@"triangle (.*[\d])([,])(.*[\d])([,])(.*[\d])");

            Match matchRun   = regexRun.Match(textBox2.Text.ToLower());
            Match matchClear = regexClear.Match(textBox2.Text.ToLower());
            Match matchReset = regexReset.Match(textBox2.Text.ToLower());
            Match matchMT    = regexMT.Match(textBox2.Text.ToLower());
            Match matchDT    = regexDT.Match(textBox2.Text.ToLower());

            Match matchR = regexR.Match(textBox2.Text.ToLower());
            Match matchC = regexC.Match(textBox2.Text.ToLower());
            Match matchT = regexT.Match(textBox2.Text.ToLower());



            if (matchRun.Success || matchClear.Success || matchReset.Success || matchMT.Success || matchDT.Success || matchR.Success || matchC.Success || matchT.Success)
            {
                //----------------RECTANGLE-----------------------//


                if (matchR.Success)
                {
                    try
                    {
                        gap = Panel_Draw.CreateGraphics();
                        // g.RotateTransform(rotation);//for rotating the shape
                        _s1 = Xaxis;
                        _s2 = Yaxis;
                        _s3 = int.Parse(matchR.Groups[1].Value);
                        _s4 = int.Parse(matchR.Groups[3].Value);

                        ShapeFactory shapeFactory = new ShapeFactory();
                        Shape        c            = shapeFactory.GetShape("rectangle");
                        c.set(fill, pcolor, _s1, _s2, _s3, _s4);

                        c.Draw(gap);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("wrong parameter: should be like this \"rectangle width, height\"");
                    }
                }

                //----------------CIRCLE-----------------------//
                else if (matchC.Success)
                {
                    try
                    {
                        gap = Panel_Draw.CreateGraphics();
                        // g.RotateTransform(rotation);//for rotating the shape
                        _s1 = Xaxis;
                        _s2 = Yaxis;
                        _s3 = int.Parse(matchC.Groups[1].Value);


                        ShapeFactory shapeFactory = new ShapeFactory();
                        Shape        c            = shapeFactory.GetShape("circle");
                        c.set(fill, pcolor, _s1, _s2, _s3 * 2, _s3 * 2);
                        //c.draw(set);
                        c.Draw(gap);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("wrong parameter: should be like this \"circle radius\"");
                    }
                }
                // ----------------TRIANGLE---------------------- -//

                else if (matchT.Success)
                {
                    try
                    {
                        gap = Panel_Draw.CreateGraphics();
                        // g.RotateTransform(rotation);//for rotating the shape
                        _s1 = Xaxis;
                        _s2 = Yaxis;

                        _s3 = int.Parse(matchT.Groups[1].Value);
                        _s4 = int.Parse(matchT.Groups[3].Value);
                        _s5 = int.Parse(matchT.Groups[5].Value);


                        xi1 = _s1;
                        yi1 = _s2;
                        xi2 = Math.Abs(_s3);
                        yi2 = _s2;

                        xii1 = _s1;
                        yii1 = _s2;
                        xii2 = _s1;
                        yii2 = Math.Abs(_s4);

                        xiii1 = Math.Abs(_s3);
                        yiii1 = _s2;
                        xiii2 = _s1;
                        yiii2 = Math.Abs(_s4);

                        ShapeFactory shapeFactory = new ShapeFactory();
                        Shape        c            = shapeFactory.GetShape("triangle"); //new rectangles();
                        c.set(fill, pcolor, xi1, yi1, xi2, yi2, xii1, yii1, xii2, yii2, xiii1, yiii1, xiii2, yiii2);
                        c.Draw(gap);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("wrong parameter: should be like this \"triangle side, side, side\"");
                    }
                }

                // ----------------CLEAR------------------------//

                else if (matchClear.Success)
                {
                    Panel_Draw.Refresh();
                    this.Panel_Draw.BackgroundImage = null;
                }

                // ----------------RUN-----------------------//

                else if (matchRun.Success)
                {
                    btn_exec_Click(this, new EventArgs());
                }
                // ----------------RESET------------------------//
                else if (matchReset.Success)
                {
                    _s1      = 0;
                    _s2      = 0;
                    Xaxis    = 0;
                    Yaxis    = 0;
                    rotation = 0;
                }

                // ----------------MOVETO------------------------//

                else if (matchMT.Success)
                {
                    try
                    {
                        _s1 = int.Parse(matchMT.Groups[1].Value);
                        _s2 = int.Parse(matchMT.Groups[3].Value);

                        Xaxis = _s1;
                        Yaxis = _s2;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                // ----------------DRAWTO------------------------//

                else if (matchDT.Success)
                {
                    try
                    {
                        Pen p = new Pen(pcolor);
                        _s1 = int.Parse(matchMT.Groups[1].Value);
                        _s2 = int.Parse(matchMT.Groups[3].Value);


                        gap.DrawLine(p, _s1, _s2, Xaxis, Yaxis);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
            else
            {
                MessageBox.Show("Command doesnot exist");
            }
        }