烟花爆炸

package zuoye;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;


import javax.swing.*;


public class Fireworks extends Applet implements MouseListener,Runnable
{


private static final long serialVersionUID = -7006042467213323331L;
int x,y;
 int top,point;
 
 public void init() 
 {
 x = 0;
 y = 0;
 //设置背景色为黑色
 setBackground(Color.black);
 addMouseListener(this);
 }


 public void paint(Graphics g) 
 { 
 
 }
 
 public static void main(String args[]) {
 Fireworks applet = new Fireworks();
 JFrame frame = new JFrame("TextAreaNew");
 frame.addWindowListener(new WindowAdapter() {
 public void windowClosing(WindowEvent e){
 System.exit(0);
 }
 });
 frame.getContentPane().add(
 applet, BorderLayout.CENTER);
 frame.setSize(800,400);
 applet.init();
 applet.start();
 frame.setVisible(true);
 }
 
 public void run()
 {
 //变量初始化
 Graphics g1;
 g1 = getGraphics();
 int y_move,y_click,x_click;
 int v;
 x_click = x;
 y_click = y;
 y_move = 400;
 v = 3;
 int r,g,b;


 while(y_move > y_click)
 { 
 g1.setColor(Color.black);
 g1.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;
 g1.setColor(new Color(r,g,b));
 g1.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;
 g1.setColor(new Color(r,g,b));
 g1.fillOval(x_click,y_move+j*5,5,5);
 }
 g1.setColor(Color.black);
 g1.fillOval(x_click,y_move+5*10,5,5);


 try 
 {
 Thread.currentThread();
Thread.sleep(v++);
 } catch (InterruptedException e) {}
 }
 
 for(int j=12;j>=0;j--)
 {
 g1.setColor(Color.black);
 g1.fillOval(x_click,y_move+(j*5),5,5);
 try 
 {
 Thread.currentThread();
Thread.sleep((v++)/3);
 } catch (InterruptedException e) {}
 }
 
 y_move = 400;
 g1.setColor(Color.black);
 while(y_move > y_click)
 { 
 g1.fillOval(x_click-2,y_move,9,5);
 y_move -= 5;
 }
 
 v = 15;
 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;
 g1.setColor(new Color(r,g,b));
 g1.drawOval(x_click-3*i,y_click-3*i,6*i,6*i);
 if(i<23) 
 {
 g1.drawOval(x_click-3*(i+1),y_click-3*(i+1),6*(i+1),6*(i+1));
 g1.drawOval(x_click-3*(i+2),y_click-3*(i+2),6*(i+2),6*(i+2));
 }
 try 
 {
 Thread.currentThread();
Thread.sleep(v++);
 } catch (InterruptedException e) {}
 g1.setColor(Color.black);
 g1.drawOval(x_click-3*i,y_click-3*i,6*i,6*i);
 
 }


}
 
 public void mousePressed(MouseEvent e)
 {
 x = e.getX();
 y = e.getY();
 Thread one;
 one = new Thread(this);
 one.start();
 one = null;
 }


 public void mouseReleased(MouseEvent e)
 { 
 }
 
 public void mouseEntered(MouseEvent e)
 {
 }
 
 public void mouseExited(MouseEvent e)
 {
 }


 public void mouseClicked(MouseEvent e)
 {
 }
 
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
烟花爆炸是指在特定的场合和时间点,通过点火引燃烟花内部的化学物质,产生美丽的火花和爆炸声音的现象。在Python中,我们可以使用一些库来模拟和实现烟花爆炸的效果。 一个常用的库是Pygame,它是一个用于开发2D游戏和多媒体应用程序的库。通过使用Pygame的粒子系统和动画效果,我们可以模拟出烟花爆炸的效果。 以下是一个简单的示例代码,展示了如何使用Pygame库创建一个基本的烟花爆炸效果: ```python import pygame import random # 初始化Pygame pygame.init() # 设置窗口大小 screen_width = 800 screen_height = 600 screen = pygame.display.set_mode((screen_width, screen_height)) pygame.display.set_caption("Fireworks") # 定义烟花粒子类 class FireworkParticle: def __init__(self, x, y): self.x = x self.y = y self.color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) self.radius = random.randint(2, 6) self.speed = random.randint(1, 5) def update(self): self.y -= self.speed def draw(self): pygame.draw.circle(screen, self.color, (int(self.x), int(self.y)), self.radius) # 创建烟花爆炸效果 def create_firework(x, y): particles = [] for _ in range(100): particle = FireworkParticle(x, y) particles.append(particle) return particles # 游戏主循环 running = True fireworks = [] while running: screen.fill((0, 0, 0)) for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame.MOUSEBUTTONDOWN: mouse_x, mouse_y = pygame.mouse.get_pos() fireworks.extend(create_firework(mouse_x, mouse_y)) for firework in fireworks: firework.update() firework.draw() fireworks = [firework for firework in fireworks if firework.y > 0] pygame.display.flip() # 退出Pygame pygame.quit() ``` 这段代码使用了Pygame库来创建一个窗口,并在窗口中模拟烟花爆炸的效果。当鼠标点击窗口时,会在点击位置创建一个烟花爆炸效果,通过不断更新和绘制粒子的位置和颜色,实现了烟花爆炸的动画效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值