Mega Code Archive

 
Categories / C# / 2D Graphics
 

Add Ellipse to path

using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms;     class Clover: Form {      public static void Main()      {           Application.Run(new Clover());      }      public Clover()      {           ResizeRedraw = true;      }      protected override void OnPaint(PaintEventArgs pea)      {           DoPage(pea.Graphics, ForeColor,ClientSize.Width, ClientSize.Height);      }             protected void DoPage(Graphics grfx, Color clr, int cx, int cy)      {           GraphicsPath path = new GraphicsPath();               path.AddEllipse(0,      cy / 3, cx / 2, cy / 3);  // Left               grfx.SetClip(path);           grfx.TranslateTransform(cx / 2, cy / 2);               Pen   pen     = new Pen(clr);           float fRadius = (float) Math.Sqrt(Math.Pow(cx / 2, 2) +                                              Math.Pow(cy / 2, 2));                 for (float fAngle = 0; fAngle <  (float) Math.PI * 2;                                   fAngle += (float) Math.PI / 180)           {                grfx.DrawLine(pen, 0, 0, fRadius * (float) Math.Cos(fAngle),                                        -fRadius * (float) Math.Sin(fAngle));           }      } }