绘制五角星

阅读量: 11 编辑

用Turtle 绘制五角星,并填充颜色

import turtle

turtle.pensize(5) 
turtle.pencolor("red") 
turtle.fillcolor("yellow") 

turtle.begin_fill() 

turtle.forward(200) 
turtle.right(144) 

turtle.forward(200) 
turtle.right(144) 

turtle.forward(200) 
turtle.right(144) 

turtle.forward(200) 
turtle.right(144) 

turtle.forward(200) 

turtle.end_fill()

# 保持窗口打开
turtle.done()

循环实现

import turtle

pen = turtle.Turtle()
pen.pensize(5)
pen.color('red','yellow')

pen.begin_fill()

for i in range(5):
    pen.forward(400)
    pen.right(144)

pen.end_fill()

爱码岛编程公众号
微信扫码关注
爱码岛编程小程序
微信扫码打开
苏ICP备13052010号
©2023 南京匠成信息科技有限公司