用java语言写一段程序画一朵玫瑰花
时间: 2023-05-24 15:02:42 浏览: 60
A:
```java
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
public class Rose extends JFrame {
public Rose() {
setSize(600, 600);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
public void paint(Graphics g) {
int width = getWidth();
int height = getHeight();
// 设定背景颜色
g.setColor(Color.BLACK);
g.fillRect(0, 0, width, height);
// 画玫瑰花
g.setColor(Color.RED);
for (double t = 0; t < 2 * Math.PI; t += 0.01) {
double x = 160 * Math.pow(Math.sin(t), 3);
double y = 130 * Math.cos(t) - 50 * Math.cos(2 * t) - 20 * Math.cos(3 * t) - 10 * Math.cos(4 * t);
g.fillOval((int) x + width / 2, (int) y + height / 3, 3, 3);
}
}
public static void main(String[] args) {
new Rose();
}
}
```
注:此程序以JFrame为基础开发,运行该程序将会打开一个绘制了玫瑰花的窗口。