java烟花编程源代码
时间: 2024-01-19 15:18:49 浏览: 27
以下是一个简单的Java烟花编程源代码示例:
```java
import java.awt.Color;
import java.util.Random;
public class Firework {
private double xPos;
private Color color;
private double maxHeight;
private double[] radians;
private double[] lens;
public Firework() {
this.xPos = 50 + Math.random() * 600;
this.color = Color.getHSBColor((float) Math.random(), 1.0f, 1.0f);
this.maxHeight = 100 + Math.random() * 400;
this.radians = new double[150];
this.lens = new double[150];
Random random = new Random();
for (int i = 0; i < 150; i++) {
radians[i] = random.nextDouble() * 2 * Math.PI;
lens[i] = random.nextDouble();
}
}
public void draw() {
if (!isFinished()) {
UI.setColor(this.color);
double left = this.xPos - this.radius;
double top = GROUND - this.ht - this.radius;
for (int i = 0; i < 150; i++) {
double x = Math.cos(radians[i]) * this.radius * lens[i] + this.xPos;
double y = Math.sin(radians[i]) * this.radius * lens[i] + GROUND - this.ht;
UI.fillOval(x - 4, y - 4, 8, 8);
}
}
}
}
```