-6

嘿朋友我正在尝试在 C# 中生成一个连续的正弦波形,我只能生成一个周期,但我希望波形是连续生成的。

这是我的代码..

public partial class Form1 : Form
{

    public Form1()
    {
        InitializeComponent();
    }


    protected override void OnPaint(PaintEventArgs e)
    {
        float x0 = 100f;
        float y0 = 100f;
        PointF[] points = new PointF[200];

        for (int j = 0; j < 200; j++)
        {
            points[j] = new PointF();
            points[j].X = x0 + j;
            points[j].Y = y0 - (float)(Math.Sin((2 * Math.PI * j) / 200) * (200 / (2 * Math.PI)));
        }

        using (Pen p = new Pen(Color.Blue))
        {
            p.EndCap = LineCap.ArrowAnchor;

            //Draw X-coordinate
            e.Graphics.DrawLine(p, x0, y0, x0 + 250, y0);

           //Draw Y-coordinate
           e.Graphics.DrawLine(p, x0, y0 + 80, x0, y0 - 80);
        }

        e.Graphics.DrawString("0", SystemFonts.DefaultFont, Brushes.Blue, x0, y0 );
        e.Graphics.DrawString("p", SystemFonts.DefaultFont, Brushes.Blue, x0 + 100, y0);
        e.Graphics.DrawString("2p", SystemFonts.DefaultFont, Brushes.Blue, x0 + 200, y0);

        e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
        e.Graphics.DrawLines(Pens.Blue, points);
        base.OnPaint(e);
    }
}
4

1 回答 1

2

只需将稍后将生成的代码放在 wave 上即可。并增加 X 轴以将其向右或向左移动。

于 2012-08-17T11:10:15.653 回答