fCraft.ShapesLib.DrawBitmap C# (CSharp) Method

DrawBitmap() private method

private DrawBitmap ( int Width, int Height ) : void
Width int
Height int
return void
        private void DrawBitmap( int Width, int Height )
        {
            // Determine the first rectangle's orientation and dimensions.
            double phi = ( 1 + Math.Sqrt( 5 ) ) / 2;
            RectOrientations orientation;
            int client_wid = Width;
            int client_hgt = Height;
            double wid, hgt;                // The rectangle's size.
            if ( client_wid > client_hgt ) {
                // Horizontal rectangle.
                orientation = RectOrientations.RemoveLeft;
                if ( client_wid / ( double )client_hgt > phi ) {
                    hgt = client_hgt;
                    wid = hgt * phi;
                } else {
                    wid = client_wid;
                    hgt = wid / phi;
                }
            } else {
                // Vertical rectangle.
                orientation = RectOrientations.RemoveTop;
                if ( client_hgt / ( double )client_wid > phi ) {
                    wid = client_wid;
                    hgt = wid * phi;
                } else {
                    hgt = client_hgt;
                    wid = hgt / phi;
                }
            }

            // Allow a margin.
            wid *= 0.9f;
            hgt *= 0.9f;

            // Center it.
            double x = ( client_wid - wid ) / 2;
            double y = ( client_hgt - hgt ) / 2;

            // Make the Bitmap.
            Bitmap bm = new Bitmap( client_wid, client_hgt );
            {
                // Draw the rectangles.
                using ( Graphics gr = Graphics.FromImage( bm ) ) {
                    gr.FillRectangle( Brushes.White, 0, 0, bm.Width, bm.Height );
                    // Draw the rectangles.
                    gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                    List<PointF> points = new List<PointF>();
                    DrawPhiRectanglesOnGraphics(points, x, y, wid, hgt, orientation );

                    // Draw the true spiral.
                    PointF start = points[0];
                    PointF origin = points[points.Count - 1];
                    float dx = start.X - origin.X;
                    float dy = start.Y - origin.Y;
                    double radius = Math.Sqrt( dx * dx + dy * dy );

                    double theta = Math.Atan2( dy, dx );
                    const int num_slices = 1000;
                    double dtheta = Math.PI / 2 / num_slices;
                    double factor = 1 - ( 1 / phi ) / num_slices * 0.78; //@
                    List<PointF> new_points = new List<PointF>();

                    // Repeat until dist is too small to see.
                    while ( radius > 0.1 ) {
                        PointF new_point = new PointF(
                            ( float )( origin.X + radius * Math.Cos( theta ) ),
                            ( float )( origin.Y + radius * Math.Sin( theta ) ) );
                        new_points.Add( new_point );
                        theta += dtheta;
                        radius *= factor;
                    }
                    gr.DrawLines( Pens.Blue, new_points.ToArray() );
                }
                bm = Crop( bm );
                bm.RotateFlip( RotateFlipType.Rotate180FlipX );
                Draw( bm );
                bm.Dispose();
            }
        }