资源简介
JAVA实现的烟花效果源码
代码片段和文件信息
package com.ice.flame;
import java.awt.Color;
import java.awt.Graphics;
import java.util.Random;
public class Firework {
private int widthheightG; //环境属性
private int Xx XyEx[] Ey[]x y; //物理属性
private int energy patch; //威力属性
private int tlength; //进度属性
private int Red Blue Green; //色彩属性
private Random random;
private PlaySounds ps=new PlaySounds(“boom.wav“);
public Firework(int a int b int g) {// 类BeaClassDemo的构造方法
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];// 初始化int数组Ex,其长度为patch
Ey = new int[patch];// 初始化int数组Ey,其长度为patch
// 随机生成不透明的 sRGB 颜色值
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; i < patch; i++) {
Ex[i] = (int) (Math.random() * energy) - energy / 2;
Ey[i] = (int) (Math.random() * energy * 7 / 8) - energy / 8;
}
}
public void start() {
t = 0;
}
public void show(Graphics g) {// 输出烟花
if (t < length) {
int ic;
double s;
Color color;
c = (int) (random.nextDouble() * 64) - 32 + Red;
if (c >= 0 && c < 256)
Red = c;
c = (int) (random.nextDouble() * 64) - 32 + Blue;
if (c >= 0 && c < 256)
Blue = c;
c = (int) (random.nextDouble() * 64) - 32 + Green;
if (c >= 0 && c < 256)
Green = c;
color = new Color(RedGreenBlue);
if(t==0)
{
System.out.println(“boom“);
new Thread(ps).start();
}
for (i = 0; i < patch; i++) {
s = (double) t / 100;
x = (int) (Ex[i] * s);
y = (int) (Ey[i] * s - G * s * s);
g.setColor(color);
g.drawLine(Xx + x Xy - y Xx +x Xy - y);
if (t >= length / 2) {
int j;
for (j = 0; j < 2; j++) {
s = (double) ((t-length/2) *2 + j) / 100;
x = (int) (Ex[i] * s);
y = (int) (Ey[i] * s - G * s * s);
g.setColor(Color.black);
g.drawLine(Xx + x Xy - y Xx + x Xy - y);
}
}
}
t++;
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 301 2017-08-10 20:52 Fireworks\.classpath
文件 385 2017-08-10 20:52 Fireworks\.project
文件 598 2017-08-10 20:52 Fireworks\.settings\org.eclipse.jdt.core.prefs
文件 2875 2017-08-10 23:15 Fireworks\bin\com\ice\flame\Firework.class
文件 631 2017-08-10 21:58 Fireworks\bin\com\ice\flame\Fireworks$1.class
文件 868 2017-08-10 21:58 Fireworks\bin\com\ice\flame\Fireworks.class
文件 2378 2017-08-10 21:58 Fireworks\bin\com\ice\flame\MyPanel.class
文件 2632 2017-08-10 21:23 Fireworks\bin\com\ice\flame\PlaySounds.class
文件 20044 2016-04-03 15:10 Fireworks\boom.wav
文件 2511 2017-08-10 23:15 Fireworks\src\com\ice\flame\Firework.java
文件 3104 2017-08-10 21:58 Fireworks\src\com\ice\flame\Fireworks.java
文件 1458 2017-08-10 20:52 Fireworks\src\com\ice\flame\PlaySounds.java
目录 0 2017-08-10 21:27 Fireworks\bin\com\ice\flame
目录 0 2017-08-10 20:52 Fireworks\src\com\ice\flame
目录 0 2017-08-10 21:23 Fireworks\bin\com\ice
目录 0 2017-08-10 20:52 Fireworks\src\com\ice
目录 0 2017-08-10 21:23 Fireworks\bin\com
目录 0 2017-08-10 20:52 Fireworks\src\com
目录 0 2017-08-10 20:52 Fireworks\.settings
目录 0 2017-08-10 21:23 Fireworks\bin
目录 0 2017-08-10 20:52 Fireworks\src
目录 0 2017-08-10 20:53 Fireworks
----------- --------- ---------- ----- ----
37785 22
评论
共有 条评论