java烟花心形代码 html爱心烟花代码( 四 )


public int speed, variability, Max_Number, Max_Energy, Max_Patch,
Max_Length, G;
public String sound;
private int width, height;
private Thread thread = null;
private BeaClassDemo bcd[];
public void init()
int i;
this.setSize(1900, 900);
width = getSize().width - 1;
height = getSize().height - 1;
speed = 1;// 烟花绽放的速度
variability = 10;
Max_Number = 980;// 可发出烟花的最大数目
Max_Energy = width + 50;
Max_Patch = 90;// 最大的斑点数
Max_Length = 90;// 斑点的最大距离
G = 150;// 向地面弯曲的力度
bcd = new BeaClassDemo[Max_Number];
for (i = 0; iMax_Number; i++)
bcd[i] = new BeaClassDemo(width, height, G);
}
public void start() {
if (thread == null) {
thread = new Thread(this);
thread.start();
}
}
@SuppressWarnings("deprecation")
public void stop() {
if (thread != null) {
thread.stop();
thread = null;
}
}
@SuppressWarnings({ "unused", "static-access" })
public void run() {
int i;
int E = (int) (Math.random() * Max_Energy * 3 / 4) + Max_Energy / 4 + 1;
int P = (int) (Math.random() * Max_Patch * 3 / 4)// 烟花的斑点数
+ Max_Patch / 4 + 1;
int L = (int) (Math.random() * Max_Length * 3 / 4)// 烟花可发射出的距离
+ Max_Length / 4 + 1;
long S = (long) (Math.random() * 10000);
boolean sleep;
Graphics g = getGraphics();
URL u = null;
while (true) {
try {
thread.sleep(1000 / speed);
catch (InterruptedException x) {
sleep = true;
for (i = 0; iMax_Number; i++)
sleep = sleepbcd[i].sleep;
if (sleepMath.random() * 100variability) {
E = (int) (Math.random() * Max_Energy * 3 / 4) + Max_Energy / 4
+ 1;
P = (int) (Math.random() * Max_Patch * 3 / 4) + Max_Patch / 4
+ 1;
L = (int) (Math.random() * Max_Length * 3 / 4) + Max_Length / 4
+ 1;
S = (long) (Math.random() * 10000);
for (i = 0; iMax_Number; i++) {
if (bcd[i].sleepMath.random() * Max_Number * L1)
bcd[i].init(E, P, L, S);
bcd[i].start();
bcd[i].show(g);
public void paint(Graphics g)
g.setColor(Color.black);
g.fillRect(0, 0, width + 1, height + 1);
class BeaClassDemo
public boolean sleep = true;
private int energy, patch, length, width, height, G, Xx, Xy, Ex[], Ey[], x,
y, Red, Blue, Green, t;
private Random random;
public BeaClassDemo(int a, int b, int g)
width = a;
height = b;
G = g;
public void init(int e, int p, int l, long seed)
int i;
energy = e;
patch = p;
length = l;
// 创建一个带种子的随机数生成器
random = new Random(seed);
Ex = new int[patch];
Ey = new int[patch];
Red = (int) (random.nextDouble() * 128) + 128;
Blue = (int) (random.nextDouble() * 128) + 128;
Green = (int) (random.nextDouble() * 128) + 128;
Xx = (int) (Math.random() * width / 2) + width / 4;
Xy = (int) (Math.random() * height / 2) + height / 4;
for (i = 0; ipatch; i++) {
Ex[i] = (int) (Math.random() * energy) - energy / 2;
Ey[i] = (int) (Math.random() * energy * 7 / 8) - energy / 8;
public void start
t = 0;
sleep = false;
public void show(Graphics g)
if (!sleep)
if (tlength)
int i, c;
double s;
Color color;
c = (int) (random.nextDouble() * 64) - 32 + Red;
if (c = 0c256)
Red = c;
c = (int) (random.nextDouble() * 64) - 32 + Blue;
if (c = 0c256)
Blue = c;
c = (int) (random.nextDouble() * 64) - 32 + Green;
if (c = 0c256)
Green = c;
color = new Color(Red, Blue, Green);
for (i = 0; ipatch; i++)
s = (double) t / 100;
x = (int) (Ex[i] * s);
y = (int) (Ey[i] * s - G * s * s);

推荐阅读