话不多说,首先先看效果图
一、导入海龟
import turtle
二、海龟初始化
pen = turtle.Pen()
turtle.bgcolor("black")
turtle.title("烟花")
pen.speed(100)
三、循环绘制烟花
for x in range(180):
step = 300
if x % 2 == 0:
pen.color("red")
step = 300
elif x % 3 ==0:
pen.color("green")
step = 250
elif x % 5 == 0:
pen.color("yellow")
step = 150
else:
pen.color("pink")
step = 100
四、定义画笔动态
pen.forward(step)
pen.dot(6)
pen.backward(step)
pen.right(2)
五、结束
turtle.done()
六、源码
import turtle
pen = turtle.Pen()
turtle.bgcolor("black")
turtle.title("烟花")
pen.speed(100)
for x in range(180):
step = 300
if x % 2 == 0:
pen.color("red")
step = 300
elif x % 3 ==0:
pen.color("green")
step = 250
elif x % 5 == 0:
pen.color("yellow")
step = 150
else:
pen.color("pink")
step = 100
pen.forward(step)
pen.dot(6)
pen.backward(step)
pen.right(2)
turtle.done()