Пример #1
0
        /// <summary>
        /// Render a star shape to buffer
        /// </summary>
        void DrawStar(PixelsBuffer buffer, Color color, Color background)
        {
            IDrawer drawer = new Drawer(buffer);
            drawer.Clear(background);

            Fill fill = new Fill(color);

            double[] coordinates = TestFactory.Star();
            TestFactory.Scale(coordinates, 2.0);

            //drawer.DrawRectangle(stroke, 0, 0, buffer.Width, buffer.Height);
            drawer.DrawPolygon(fill, coordinates);
        }
Пример #2
0
        void DrawLion(PixelsBuffer buffer, int x, int y)
        {
            //create a new drawing context
            //PixelBuffer buffer = new PixelBuffer(400, 400);
            IDrawer drawer = new Drawer(buffer);

            //get coordinates and colors
            double[][] polygons = LionPathHelper.GetLionPolygons();
            Cross.Drawing.Color[] colors = LionPathHelper.GetLionColors();

            //iterate all polygons and draw them
            double[] coordinates = null;
            drawer.Translate(x, y);
            for (int i = 0; i < polygons.Length; i++)
            {
                coordinates = polygons[i];
                Fill fill = new Fill(colors[i]);
                drawer.DrawPolygon(fill, coordinates);
            }
        }
        void DrawLion()
        {
            //create a new drawing context
            PixelsBuffer buffer = new PixelsBuffer(400, 400);
            IDrawer drawer = new Drawer(buffer);
            drawer.Clear(Colors.White);

            //get coordinates and colors
            double[][] polygons = LionPathHelper.GetLionPolygons();
            Color[] colors = LionPathHelper.GetLionColors();

            //iterate all polygons and draw them
            double[] coordinates = null;
            for (int i = 0; i < polygons.Length; i++)
            {
                coordinates = polygons[i];
                Fill fill = new Fill(colors[i]);
                drawer.DrawPolygon(fill, coordinates);
            }

            //show to screen
            DisplayBuffer(buffer);
        }
        private void btnDrawPolygon_Click(object sender, EventArgs e)
        {
            //create a new drawing context
            PixelsBuffer buffer = new PixelsBuffer(400, 400);
            IDrawer drawer = new Drawer(buffer);
            drawer.Clear(Colors.White);

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

            //populate polygon coordinate data
            double[] coordinates = new double[]
            {
                30, 300,
                150, 40,
                300, 260,
                130, 200,
                //30, 300 //the last point is omitted to show that the end point is important
                          //for rendering stroke
            };

            //draw content
            drawer.DrawPolygon(fill, coordinates);

            //show to screen
            DisplayBuffer(buffer);
        }
        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);
            }
        }