Ellipse with DrawLines : Curve « 2D Graphics « C# / C Sharp






Ellipse with DrawLines

 

using System;
using System.Drawing;
using System.Windows.Forms;
   
class PolyEllipse: Form
{
     public static void Main()
     {
          Application.Run(new PolyEllipse());
     }
     public PolyEllipse()
     {
          Text = "Ellipse with DrawLines";
          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)
     {
          int      iNum = 2 * (cx + cy);
          PointF[] aptf = new PointF[iNum];
   
          for (int i = 0; i < iNum; i++)
          {
               double dAng = i * 2 * Math.PI / (iNum - 1);
   
               aptf[i].X = (cx - 1) / 2f * (1 + (float)Math.Cos(dAng));
               aptf[i].Y = (cy - 1) / 2f * (1 + (float)Math.Sin(dAng));
          }
          grfx.DrawLines(new Pen(clr), aptf);
     }
}

 








Related examples in the same category

1.Sine Curve
2.Spiral
3.Bezier (Mouse Defines Control Points)
4.Draw closed curveDraw closed curve
5.Click on the form to draw curveClick on the form to draw curve