fCraft.ShapesLib.DrawRegularPolygon C# (CSharp) Method

DrawRegularPolygon() public method

public DrawRegularPolygon ( int sides, int startingAngle, bool FillPoly ) : void
sides int
startingAngle int
FillPoly bool
return void
        public void DrawRegularPolygon( int sides, int startingAngle, bool FillPoly )
        {
            //Get the location for each vertex of the polygon
            Point center = new Point( Radius / 2, Radius / 2 );
            Point[] verticies = CalculateVertices( sides, Radius / 2, startingAngle, center );

            //Render the polygon
            Bitmap polygon = new Bitmap( Radius + 1, Radius + 1 );
            using ( Graphics g = Graphics.FromImage( polygon ) ) {
                g.FillRectangle( Brushes.White, 0, 0, polygon.Width, polygon.Height );
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                g.DrawPolygon( Pens.Black, verticies );
                if ( FillPoly ) {
                    SolidBrush brush = new SolidBrush( System.Drawing.Color.Black );
                    g.FillPolygon( brush, verticies );
                }
            }
            polygon = Crop( polygon );
            polygon.RotateFlip( RotateFlipType.Rotate180FlipX );
            Draw( polygon );
            polygon.Dispose();
        }

Usage Example

Example #1
0
        static void Draw2DCallback( Player player, Vector3I[] marks, object tag )
        {
            Block block = new Block();
            Draw2DData data = ( Draw2DData )tag;
            int radius = data.Radius;
            int Points = data.Points;
            bool fill = data.Fill;
            string Shape = data.Shape;
            if ( player.LastUsedBlockType == Block.Undefined ) {
                block = Block.Stone;
            } else {
                block = player.LastUsedBlockType;
            }
            Direction direction = DirectionFinder.GetDirection( marks );
            try {
                ShapesLib lib = new ShapesLib( block, marks, player, radius, direction );
                switch ( Shape.ToLower() ) {
                    case "polygon":
                        lib.DrawRegularPolygon( Points, 18, fill );
                        break;
                    case "star":
                        lib.DrawStar( Points, radius, fill );
                        break;
                    case "spiral":
                        lib.DrawSpiral();
                        break;
                    default:
                        player.Message( "&WUnknown shape" );
                        CdDraw2D.PrintUsage( player );
                        lib = null;
                        return;
                }

                if ( lib.blockCount > 0 ) {
                    player.Message( "/Draw2D: Drawing {0} with a size of '{1}' using {2} blocks of {3}",
                        Shape,
                        radius,
                        lib.blockCount,
                        block.ToString() );
                } else {
                    player.Message( "&WNo direction was set" );
                }
                lib = null; //get lost
            } catch ( Exception e ) {
                player.Message( e.Message );
            }
        }