1024版烟花--2的10次方 快乐

效果:

 

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class App extends Frame {
    //背景
    int b1x[] = {0, 666, 666, 0};
    int b1y[] = {00, 0, 666, 666};
    Thread thread;
    int count = 8;//个数

    App() {
        setLayout(new FlowLayout());
        setTitle("1024快乐");
        setSize(666, 666);
        setVisible(true);
        setLocation(850,100);
    }

    public void paint(Graphics g) {
        g.setColor(Color.BLACK);                   // 描画颜色
        g.fillPolygon(b1x, b1y, 4);              // 描画

        while (true) {
            g.setColor(Color.BLACK);                   // 描画颜色
            g.fillPolygon(b1x, b1y, 4);              // 描画
            int flowerx = (int) (Math.random() * 666);//x坐标
            int flowery = 100 + (int) (Math.random() * 300); //最终y坐标
            int movey = 666;//弹移动变量
            while (movey >= flowery)//当
            {
                g.setColor(Color.BLACK);                   // 描画颜色
                g.fillPolygon(b1x, b1y, 4);              // 描画
                g.setColor(Color.WHITE);                   // 弹颜色白色
                g.drawString("1024",flowerx,movey);
                try {
                    Thread.sleep(20);//延时
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                //用黑色抹去弹踪迹
                g.setColor(Color.BLACK);
                g.drawString("1024",flowerx,movey + 1200 / flowery);

                movey -= 1200 / flowery;//向上移动幅度
            }
            g.setColor(Color.WHITE);                   // 弹颜色白色
            g.fillOval(flowerx, flowery, 1600 / flowery, 1600 / flowery);//弹大小
            try {
                Thread.sleep(30);//延时

            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            //抹去弹
            g.setColor(Color.BLACK);                   // 描画颜色
            g.fillPolygon(b1x, b1y, 4);              // 描画
            //炸出以弹终点坐标为圆心的40个小
            for (int i = 0; i < 10; i++) {//

                int r = 3 + (int) (Math.random() * 400 / flowery);//花骨朵半径

                //右下象限
                Color c1 = new Color((int) (Math.random() * 255), (int) (Math.random() * 255), (int) (Math.random() * 255));//花骨朵颜色
                g.setColor(c1);
                g.fillOval(flowerx + (int) (Math.random() * r * 50), flowery + (int) (Math.random() * r * 50), r, r);
                g.drawString("1024",flowerx + (int) (Math.random() * r * 50), flowery + (int) (Math.random() * r * 50));

                //左上象限
                Color c2 = new Color((int) (Math.random() * 255), (int) (Math.random() * 255), (int) (Math.random() * 255));//花骨朵颜色
                g.setColor(c2);
                g.fillOval(flowerx - (int) (Math.random() * r * 50), flowery - (int) (Math.random() * r * 50), r, r);
                g.drawString("8",flowerx - (int) (Math.random() * r * 50), flowery - (int) (Math.random() * r * 50));
                //左下象限
                Color c3 = new Color((int) (Math.random() * 255), (int) (Math.random() * 255), (int) (Math.random() * 255));//花骨朵颜色
                g.setColor(c3);
                g.fillOval(flowerx - (int) (Math.random() * r * 50), flowery + (int) (Math.random() * r * 50), r, r);
                g.drawString("16",flowerx - (int) (Math.random() * r * 50), flowery + (int) (Math.random() * r * 50));
                //右上象限
                Color c4 = new Color((int) (Math.random() * 255), (int) (Math.random() * 255), (int) (Math.random() * 255));//花骨朵颜色
                g.setColor(c4);
                g.fillOval(flowerx + (int) (Math.random() * r * 50), flowery - (int) (Math.random() * r * 50), r, r);
                g.drawString("32",flowerx + (int) (Math.random() * r * 50), flowery - (int) (Math.random() * r * 50));
            }
            try {
                Thread.sleep(600);//延时

            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            count--;//减1
            if (count <= 0) break;//放完退出循环
        }
        System.exit(0); //退出窗体
    }


    class WinAdapter extends WindowAdapter {
        public void windowClosing(WindowEvent we) {
            System.exit(0);
        }
    }

    public static void main(String[] args) {
        App f = new App();
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

乘风御浪云帆之上

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值