C# 画满屏玫瑰代码
时间: 2023-07-12 11:04:54 浏览: 128
以下是使用C#绘制满屏玫瑰的代码示例:
```csharp
using System;
using System.Drawing;
using System.Windows.Forms;
namespace RoseExample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.BackColor = Color.Black;
this.DoubleBuffered = true;
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
int width = ClientSize.Width;
int height = ClientSize.Height;
// 设置颜色
Pen pen = new Pen(Color.White);
pen.Width = 2;
// 绘制玫瑰花
for (double t = 0; t < 360; t += 0.01)
{
double a = Math.PI * t / 180;
double r = 300 * Math.Sin(3 * a);
double x = r * Math.Cos(a) + width / 2;
double y = r * Math.Sin(a) + height / 2;
g.DrawEllipse(pen, (float)x, (float)y, 2, 2);
}
}
}
}
```
在此示例中,我们使用 `OnPaint` 事件处理程序绘制玫瑰。我们使用 `Graphics` 对象来绘制每个点,并使用 `Pen` 对象设置其颜色和线条宽度。最后,我们使用 `DrawEllipse` 方法在指定的坐标上绘制一个小圆点,形成玫瑰花的形状。
你可以在 `Form1` 类的构造函数中设置窗体的背景色为黑色,并启用双缓冲来减少图像闪烁。运行程序后,你会看到一个满屏的玫瑰花。