简易电子烟花,上课演示的不二之选,学完去老师同学面前秀一手吧

···这不快过年了吗?

···大家肯定很久没放过烟花了,种种原因让这个每年过年的必备项目离我们越来越远,有点可惜~

···不过问题不大,咱可以自己整一场小型烟花自己欣赏,或者叫上喜欢的人一起观看也可以哦~

开整!

先看看效果

请添加图片描述
不确定,但好像还行哈哈

导入库

import random
import pygame as py
import tkinter as tk
from time import time, sleep
from tkinter import filedialog
from PIL import Image, ImageTk
from math import sin, cos, radians
from random import choice, uniform, randint

源码·点击领取即可

实现代码

生成随机颜色


def randomcolor():
    #生成随机颜色
    colArr = ['1','2','3','4','5','6','7','8','9','A','B','C','D','E','F']
    color = ""
    for i in range(6):
        color += colArr[random.randint(0,14)]
    return "#"+color

GRAVITY = 0.06
#重力变量
colors = ['red', 'blue', 'yellow', 'white', 'green', 'orange', 'purple', 'seagreen','indigo', 'cornflowerblue', 'pink']
#颜色列表

属性

Generic class for particles
particles are emitted almost randomly on the sky, forming a round of circle (a star) before falling and getting removed
from canvas
Attributes(属性):
    - id: 粒子的id
    - x, y: 粒子的坐标
    - vx, vy: 粒子在对应坐标的变化速度
    - total:一颗烟花里的粒子总数
    - age: 粒子在画布上停留的时间
    - color: 自我移植
    - cv: 画布
    - lifespan: 粒子在画布上停留的时间

粒子运动的速度
这个里面的新年快乐是可以自己更改的哦

python学习交流Q群:465688591 ### 源码领取
class part:
#为每一个烟花绽放出来的粒子单独构建一个类的对象 ,每个粒子都会有一些重要的属性,决定它的外观(大小、颜色)、移动速度等
    def __init__(self, cv, idx, total, explosion_speed
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值