fCraft.ShapesLib.DrawStar C# (CSharp) Method

DrawStar() public method

public DrawStar ( int num_points, int Radius, bool Fill ) : void
num_points int
Radius int
Fill bool
return void
        public void DrawStar( int num_points, int Radius, bool Fill )
        {
            Bitmap bmp = new Bitmap( Radius, Radius );
            using ( Graphics g = Graphics.FromImage( bmp ) ) {
                g.FillRectangle( Brushes.White, 0, 0, bmp.Width, bmp.Height );
                // Get the star's points.
                PointF[] star_points = MakeStarPoints( -Math.PI / 2, num_points, Radius / 2 );

                // Draw the star.
                SolidBrush brush = new SolidBrush( System.Drawing.Color.Black );
                if ( Fill ) {
                    g.FillPolygon( brush, star_points );
                }
                g.DrawPolygon( Pens.Black, star_points );
                bmp = Crop( bmp );
                bmp.RotateFlip( RotateFlipType.Rotate180FlipX );
                Draw( bmp );
                bmp.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 );
            }
        }