用Python制作粒子烟花,提前开始跨年了~

前言

跨年倒计时20天?我已经开始整烟花了,虽然不是很好看吧,但是也能将就看看 😥

这个的背景图,音乐,还有文字都是可以自己修改的哦

效果展示

在这里插入图片描述

导入库

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
  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值