Spiral : Curve « 2D Graphics « C# / C Sharp






Spiral

 

using System;
using System.Drawing;
using System.Windows.Forms;
   
class Spiral: Form
{
     public static void Main()
     {
          Application.Run(new Spiral());
     }
     public Spiral()
     {
          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)
     {
          const int iNumRevs   = 20;
          int       iNumPoints = iNumRevs * 2 * (cx + cy);
          PointF[]  aptf       = new PointF[iNumPoints];
          float     fAngle, fScale;
   
          for (int i = 0; i < iNumPoints; i++)
          {
               fAngle = (float)(i * 2 * Math.PI /(iNumPoints / iNumRevs));
               fScale = 1 - (float)i / iNumPoints;
   
               aptf[i].X = (float)(cx / 2 * (1 + fScale * Math.Cos(fAngle)));
               aptf[i].Y = (float)(cy / 2 * (1 + fScale * Math.Sin(fAngle)));
          }
          grfx.DrawLines(new Pen(clr), aptf);
     }
}

 








Related examples in the same category

1.Sine Curve
2.Ellipse with DrawLines
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