turtle绘制五角星

代码演示

import turtle         #导入turtle库
t = turtle.Pen()
t.fillcolor("red")      #设置填充颜色
t.begin_fill()        #开始填充
for i in range(5):    
    t.forward(300)      #向前移动300
    t.right(180-180/5)   #180-五角星的内角和/5
t.end_fill()         #结束填充
turtle.done()

结果演示

posted @ 2024-02-29 09:20  捞月亮的小北  阅读(89)  评论(0编辑  收藏  举报