9.C#编程学习——sin曲线

源码

usingSystem;

usingSystem.Drawing;

usingSystem.Windows.Forms;

 

classSineCurve : PrintableForm

{

    publicnewstaticvoidMain()

    {

        Application.Run(newSineCurve());

    }

    public SineCurve()

    {

        Text = "Sine Curve";

    }

    protectedoverridevoid DoPage(Graphics grfx, Color clr, int cx, int cy)

    {

        PointF[] aptf = newPointF[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(newPen(clr), aptf);

    }

}