用户:
心灵终结—烧饼车查看:1 回复:2 评论:1 创建时间:2023-10-21T22:18:34
【作品展示】

【作品介绍】
sdaa
【作品源代码】
import turtle
jkl = [(-100), (-85), (-85), (-100)]
喵 = [180, 150, 120, 100]
tel = [305, 30, 3, 300]
t = turtle.Pen()
t.speed(5)
# 绘制旗面
t.penup()
t.goto((-200), 200)
t.pendown()
t.begin_fill()
t.fillcolor('red')
t.pencolor('red')
for i in range(2):
t.forward(438)
t.right(90)
t.forward(292)
t.right(90)
t.end_fill()
# 绘制主五角星
t.fillcolor('yellow')
t.pencolor('yellow')
t.penup()
t.goto((-170), 145)
t.pendown()
t.begin_fill()
for x in range(5):
t.forward(50)
t.right(144)
t.end_fill()
for h in range(4):
t.penup()
t.goto(jkl[h], 喵[h])
t.setheading(tel[h])
t.pendown()
t.begin_fill()
for s in range(5):
t.forward(20)
t.right(144)
t.end_fill()
t.hideturtle()
turtle.done()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn
刘某文看起来你正在使用Python的turtle库来绘制一个旗帜,包括一个旗面和一个主五角星,以及一些小五角星。你的代码看起来没有明显的错误,但是在你绘制小五角星的循环中,你需要将t.setheading(tel[h])替换为t.setheading(90 - tel[h])。因为turtle库中的setheading函数是设置当前朝向,参数为正表示逆时针旋转,参数为负表示顺时针旋转。
这是修改后的代码:
pythonimport turtle
jkl = [(-100), (-85), (-85), (-100)]
喵 = [180, 150, 120, 100]
tel = [305, 30, 3, 300]
t = turtle.Turtle()
t.speed(5)
# 绘制旗面
t.penup()
t.goto((-200), 200)
t.pendown()
t.begin_fill()
t.fillcolor('red')
t.pencolor('red')
for i in range(2):
t.forward(438)
t.right(90)
t.forward(292)
t.right(90)
t.end_fill()
# 绘制主五角星
t.fillcolor('yellow')
t.pencolor('yellow')
t.penup()
t.goto((-170), 145)
t.pendown()
t.begin_fill()
for x in range(5):
t.forward(50)
t.right(144)
t.end_fill()
for h in range(4):
t.penup()
t.goto(jkl[h], 喵[h])
t.setheading(90 - tel[h]) # 修改此处代码
t.pendown()
t.begin_fill()
for s in range(5):
t.forward(20)
t.right(144)
t.end_fill()
t.hideturtle()
turtle.done()
这样应该能正确地绘制出你想要的旗帜。
点赞2
评论