话不多说,先上代码:
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
效果图