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






Sine Curve

 


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

 








Related examples in the same category

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