分享自制的python烟花(2025基础款)

话不多说,先上代码:

from turtle import *
import random as r
import math as m
import time as t
aws=int(input("请输入要放的烟花数量:"))
title("firework(烟花——ZH-CN)")
hideturtle()
speed(-1)
bgcolor("black")
t2=Turtle()
n=['blue','green','red','skyblue','yellow','purple','brown','wheat','pink']
now_X=r.randint(-500, 500)
now_Y=r.randint(100, 300)
def random():
    pu()
    goto(now_X,now_Y)
    pd()

def firework(): #定义烟花函数
    color(n[r.randint(0,8)])
    for _ in range(1,30):
        circle(10,19)
        fd(100)
        goto(now_X, now_Y)
def now_time():
    year = t.strftime("%Y")
    month = t.strftime("%m")
    day = t.strftime("%d")
    hour = t.strftime("%H")
    minute = t.strftime("%M")
    second = t.strftime("%S")
    t2.hideturtle()
    t2.color("white")
    t2.write(f"X:{now_X} Y:{now_Y}")
    t2.pu()
    t2.goto(300,-400)
    t2.pd()
    t2.write(f" TIME : {year} 年  {month} 月  {day} 日 \n {hour} : {minute} : {second}")
b=0
for i in range(aws):
    random()
    pu()
    goto(0, -500)
    pd()
    firework()
    now_X = r.randint(-500, 500)
    now_Y = r.randint(100, 300)
    clear()
    t2.clear()
    pu()
    t2.goto(400,-400)
    pd()
    now_time()
    t.sleep(1)
    b+=1
    c=b/aws*100
    print(f"已经放了{b}个烟花,占要放总数的{c}%")
done()
print("提示:烟花已放完")








from turtle import *
import random as r
import math as m
import time as t
aws=int(input("请输入要放的烟花数量:"))
title("firework(烟花——ZH-CN)")
hideturtle()
speed(-1)
bgcolor("black")
t2=Turtle()
n=['blue','green','red','skyblue','yellow','purple','brown','wheat','pink']
now_X=r.randint(-500, 500)
now_Y=r.randint(100, 300)
def random():
    pu()
    goto(now_X,now_Y)
    pd()

def firework(): #定义烟花函数
    color(n[r.randint(0,8)])
    for _ in range(1,30):
        circle(10,19)
        fd(100)
        goto(now_X, now_Y)
def now_time():
    year = t.strftime("%Y")
    month = t.strftime("%m")
    day = t.strftime("%d")
    hour = t.strftime("%H")
    minute = t.strftime("%M")
    second = t.strftime("%S")
    t2.hideturtle()
    t2.color("white")
    t2.write(f"X:{now_X} Y:{now_Y}")
    t2.pu()
    t2.goto(300,-400)
    t2.pd()
    t2.write(f" TIME : {year} 年  {month} 月  {day} 日 \n {hour} : {minute} : {second}")
b=0
for i in range(aws):
    random()
    pu()
    goto(0, -500)
    pd()
    firework()
    now_X = r.randint(-500, 500)
    now_Y = r.randint(100, 300)
    clear()
    t2.clear()
    pu()
    t2.goto(400,-400)
    pd()
    now_time()
    t.sleep(1)
    b+=1
    c=b/aws*100
    print(f"已经放了{b}个烟花,占要放总数的{c}%")
done()
print("提示:烟花已放完")


 

代码中提到了turtle,没有的参照以下命令安装

pip install turtle

效果图

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值