一、代码如下:
#绘制一个五角星
import turtle
turtle.fillcolor(“red”)#填充颜色
turtle.up()#提笔
turtle.goto(-150,0)#移动笔尖
turtle.down()#落笔
turtle.begin_fill()#开始填充
turtle.forward(300)#向前移动300
turtle.right(144)#顺时针旋转144
turtle.forward(300)#向前移动300
turtle.right(144)#顺时针旋转144
turtle.forward(300)#向前移动300
turtle.right(144)#顺时针旋转144
turtle.forward(300)#向前移动300
turtle.right(144)#顺时针旋转144
turtle.forward(300)#向前移动300
turtle.right(144)#顺时针旋转144
turtle.end_fill()#结束填充
turtle.done()#落笔
二、运行结果展示:
turtle.forward(300)#向前移动300
turtle.right(144)#顺时针旋转144
在代码中重复出现5次,可以用for循环进行写:
import turtle
a = turtle.Pen()
a.fillcolor(“red”)#设置填充的颜色
a.begin_fill()#开始填充
for i in range(5):
a.forward(300)#向前移动300
a.right(180-180/5)#180-180/5表示的是180-五角星的内和/5
a.end_fill()#结束填充
turtle.done()