python基础编程:python如何实现浪漫的烟花秀(附代码)

python基础编程:python如何实现浪漫的烟花秀(附代码)_第1张图片

 不废话,直接上代码:

import turtle

screen = turtle.Screen()
pen = turtle.Turtle()

pen.pensize(3)
pen.speed(10)

screen.bgcolor("black")

def fireworks():
    for i in range(30):
        pen.color("red")
        pen.forward(200)
        pen.left(170)
    pen.penup()
    pen.setpos(0, 0)
    pen.pendown()
    for i in range(30):
        pen.color("yellow")
        pen.forward(200)
        pen.left(170)
    pen.penup()
    pen.setpos(0, 0)
    pen.pendown()
    for i in range(30):
        pen.color("blue")
        pen.forward(200)
        pen.left(170)
    pen.penup()
    pen.setpos(0, 0)
    pen.pendown()
    for i in range(30):
        pen.color("purple")
        pen.forward(200)
        pen.left(170)
    pen.penup()
    pen.setpos(0, 0)
    pen.pendown()

for i in range(10):
    fireworks()

screen.mainloop()

喜欢的关注下。

你可能感兴趣的:(python,python,开发语言)