其他分享
首页 > 其他分享> > 绘制一个五角星和六角形

绘制一个五角星和六角形

作者:互联网

绘制一个五角星。(注:并在顶端加上:“我爱你中国”这几个字)

代码为:

import turtle
turtle.fillcolor("red")
turtle.begin_fill()
while True:
    turtle.forward(220)
    turtle.right(144)
    if abs(turtle.pos()) < 1:
        break
turtle.end_fill()
turtle.up()
turtle.goto(60,90)
turtle.write("我爱你中国",font=('宋体',10))
turtle.ht()
turtle.done()

绘制一个六角形(并填充颜色为蓝色)。

代码为:

import turtle
turtle.fillcolor("DeepSkyBlue")
turtle.begin_fill()
turtle.left(30)
turtle.forward(144)
for i in range(5):
    turtle.right(60)
    turtle.forward(144)
turtle.forward(144)
turtle.right(120)
turtle.forward(144)
for i in range(5):
    turtle.left(60)
    turtle.forward(144)
    turtle.right(120)
    turtle.forward(144)
turtle.end_fill()
turtle.done()

标签:turtle,144,right,60,五角星,forward,绘制,六角形,fill
来源: https://blog.csdn.net/m0_59854777/article/details/121728603