琴终 2015-02-18 06:08 采纳率: 0%
浏览 4763

不知道是不是笛卡尔心形函数C语言的编程,,

private void Form4_Load(object sender, EventArgs e)
{
this.BackColor = Color.Black;
this.Size = new Size(400, 400);
Panel panel = new Panel();
panel.Size = new Size(350, 350);
panel.Paint += new PaintEventHandler(panel_Paint);
panel.Location = new Point((this.ClientRectangle.Width - panel.Width) / 2, (this.ClientRectangle.Height - panel.Height) / 2);
this.Controls.Add(panel);
}

    void panel_Paint(object sender, PaintEventArgs e)
    {
        e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
        double x, y, r;
        int w = e.ClipRectangle.Width;
        int h = e.ClipRectangle.Height;
        for (int i = 0; i <= 90; i++)
        {
            for (int j = 0; j <= 90; j++)
            {
                //转换为直角坐标系,设置偏移量,使图像居中
                r = Math.PI / 45 * i * (1 - Math.Sin(Math.PI / 45 * j)) * 19;
                x = r * Math.Cos(Math.PI / 45 * j) * Math.Sin(Math.PI / 45 * i) + w / 2;
                y = -r * Math.Sin(Math.PI / 45 * j) + h / 4;
                using (Brush brush = new SolidBrush(Color.Red))
                {
                    e.Graphics.FillEllipse(brush, (float)x, (float)y, 2f, 2f);
                    e.Graphics.FillEllipse(brush, (float)x, (float)y, 1f, 1f);
                }
            }
        }
    }

展开全部

  • 写回答

1条回答 默认 最新

  • devmiao 2015-02-18 06:14
    关注

    运行下就知道了,这是C#不是C。

    评论
编辑
预览

报告相同问题?