Beispiel #1
0
        /// <summary>
        /// Gets data of the polygon to draw
        /// </summary>
        double[] GetPath()
        {
            double[] result = null;

            switch (lstShapes.SelectedIndex)
            {
            case 0:    //rectangle
                result = new double[] { 0, 0, w, 0, w, h, 0, h, 0, 0 };
                break;

            case 1:    //triangle
                result = TestFactory.Triangle();
                result = TestFactory.Scale(result, 10);
                break;

            case 2:    //star
                result = TestFactory.Star();
                result = TestFactory.Scale(result, 12);
                result = TestFactory.Offset(result, 0, -100);
                break;

            case 3:    //crown
                result = TestFactory.Crown();
                result = TestFactory.Scale(result, 10);
                result = TestFactory.Offset(result, 0, -70);
                break;

            case 4:    //circle pattern 1
                result = TestFactory.CirclePattern1(w, h);
                break;

            case 5:    //circle pattern 2
                result = TestFactory.CirclePattern2(w, h);
                break;

            case 6:    //complex 1
                result = TestFactory.Complex1();
                result = TestFactory.Scale(result, 1.3);
                result = TestFactory.Offset(result, 30, 150);
                break;

            case 7:    //complex 2
                result = TestFactory.Complex2();
                result = TestFactory.Scale(result, 8);
                result = TestFactory.Offset(result, -60, -450);
                break;

            case 8:    //complex 3
                result = TestFactory.Complex3();
                //result = TestFactory.Scale(result, 1);
                result = TestFactory.Offset(result, 0, -50);
                break;
            }

            return(result);
        }
        private void btnDrawTest_Click(object sender, EventArgs e)
        {
            if (lstTests.SelectedIndex < 0)
            {
                lstTests.SelectedIndex = 0;
            }

            //create a new drawing context
            PixelsBuffer buffer = new PixelsBuffer(600, 600);
            IDrawer      drawer = new Drawer(buffer);

            drawer.Clear(Colors.White);

            //create fill for drawing
            Fill fill = Fills.Black;

            //populate polygon coordinate data
            double[] coordinates = null;
            switch (lstTests.SelectedIndex)
            {
            case 0:
                coordinates = TestFactory.Triangle();
                TestFactory.Scale(coordinates, 5.0);
                break;

            case 1:
                coordinates = TestFactory.Star();
                TestFactory.Scale(coordinates, 5.0);
                break;

            case 2:
                coordinates = TestFactory.Crown();
                TestFactory.Scale(coordinates, 5.0);
                break;

            case 3:
                coordinates = TestFactory.CirclePattern1(buffer.Width, buffer.Height);
                break;

            case 4:
                coordinates = TestFactory.CirclePattern2(buffer.Width, buffer.Height);
                break;

            case 5:
                coordinates = TestFactory.Complex1();
                break;

            case 6:
                coordinates = TestFactory.Complex2();
                break;

            case 7:
                coordinates = TestFactory.Complex3();
                break;

            case 8:
                DrawLion();
                break;
            }


            if (coordinates != null)
            {
                //draw content
                drawer.DrawPolygon(fill, coordinates);

                //show to screen
                DisplayBuffer(buffer);
            }
        }