家乡春节已经禁炮多年了,只能放点电子的了
//主体
@Override
public void run() {
Graphics pen = this.getGraphics();
int y_move = 400;
int y_click = y;
int x_click = x;
int leave = 3;
int r,g,b;
//烟花运动轨迹(上升)
while(y_move > y_click){
pen.setColor(Color.black);
pen.fillOval(x_click,y_move,5,5);
y_move -= 5;
//使同一束烟花处于相同色系
r = (((int)Math.round(Math.random()*4321))%200)+55;
g = (((int)Math.round(Math.random()*4321))%200)+55;
b = (((int)Math.round(Math.random()*4321))%200)+55;
pen.setColor(new Color(r,g,b));
pen.fillOval(x_click,y_move,5,5);
for(int j = 0;j <= 10;j++){
if(r > 55)r -= 20;
if(g > 55)g -= 20;
if(b > 55)b -= 20;
pen.setColor(new Color(r,g,b));
pen.fillOval(x_click,y_move+j*5,5,5);
}
//删掉末尾烟花块
pen.setColor(Color.black);
pen.fillOval(x_click,y_move+5*10,5,5);
try{
Thread.currentThread().sleep(leave++);
}catch (InterruptedException e){
e.printStackTrace();
}
}
//从末尾开始删除烟花束
for(int j = 10; j >= 0;j--){
pen.setColor(Color.black);
pen.fillOval(x_click,y_move+j*5,5,5);
try{
Thread.currentThread().sleep((leave++)/3);
}catch (InterruptedException e){
e.printStackTrace();
}
}
pen.setColor(Color.black);
leave = 15;
//25*6是烟花最大半径,烟花轨迹(炸裂)
for(int i = 0;i<=25;i++){
//使同一圈烟花处于相同色
r = (((int)Math.round(Math.random()*4321))%200)+55;
g = (((int)Math.round(Math.random()*4321))%200)+55;
b = (((int)Math.round(Math.random()*4321))%200)+55;
pen.setColor(new Color(r,g,b));
pen.drawOval(x_click-3*i,y_click-3*i,6*i,6*i);
//增加小半径烟花圈数
if(i<23){
pen.drawOval(x_click-3*(i+1),y_click-3*(i+1),6*(i+1),6*(i+1));
pen.drawOval(x_click-3*(i+2),y_click-3*(i+2),6*(i+2),6*(i+2));
}
try{
Thread.currentThread().sleep(leave++);
}catch (InterruptedException e){
e.printStackTrace();
}
pen.setColor(Color.black);
pen.drawOval(x_click-3*i,y_click-3*i,6*i,6*i);
}
}
实现效果
哈哈哈十分敷衍