填充蟒蛇中不寻常的形状
我正在尝试用海龟制作迪士尼介绍,但是城堡的这一部分不想正确填充,我不明白为什么。
这是代码:
import turtle
t1 = turtle.Turtle()
t2 = turtle.Turtle()
background_color = "#1b3f9f"
castle_color = "#78b3d3"
def goto_168_64():
t1.penup()
t2.penup()
t1.goto(168,64)
t2.goto(-168,64)
t1.pendown()
t2.pendown()
def background():
t1.hideturtle()
t2.hideturtle()
turtle.bgcolor(background_color)
def draw():
goto_168_64()
t1.fillcolor(castle_color)
t2.fillcolor(castle_color)
t1.begin_fill()
t2.begin_fill()
t1.goto(40,64)
t2.goto(-40,64)
t1.setheading(90)
t2.setheading(90)
for x in range(23):
t1.forward(2)
t2.forward(2)
t1.left(4)
t2.right(4)
t1.setheading(180)
t2.setheading(0)
t1.forward(25)
t2.forward(25)
goto_168_64()
t1.setheading(180)
t2.setheading(0)
for x in range(23):
t1.forward(2)
t2.forward(2)
t1.right(4)
t2.left(4)
t1.setheading(90)
t2.setheading(90)
t1.forward(10)
t2.forward(10)
t1.setheading(180)
t2.setheading(0)
t1.forward(140)
t2.forward(140)
t1.penup()
t2.penup()
t1.goto(0,103)
t2.goto(0,103)
t1.pendown()
t2.pendown()
t1.goto(0,93)
t2.goto(0,93)
t1.end_fill()
t2.end_fill()
background()
draw()
turtle.mainloop()
这是输出的图片:
I am trying to make the Disney intro in turtle, but this part of the castle doesn't want to fill properly and I don't understand why.
Here is the code:
import turtle
t1 = turtle.Turtle()
t2 = turtle.Turtle()
background_color = "#1b3f9f"
castle_color = "#78b3d3"
def goto_168_64():
t1.penup()
t2.penup()
t1.goto(168,64)
t2.goto(-168,64)
t1.pendown()
t2.pendown()
def background():
t1.hideturtle()
t2.hideturtle()
turtle.bgcolor(background_color)
def draw():
goto_168_64()
t1.fillcolor(castle_color)
t2.fillcolor(castle_color)
t1.begin_fill()
t2.begin_fill()
t1.goto(40,64)
t2.goto(-40,64)
t1.setheading(90)
t2.setheading(90)
for x in range(23):
t1.forward(2)
t2.forward(2)
t1.left(4)
t2.right(4)
t1.setheading(180)
t2.setheading(0)
t1.forward(25)
t2.forward(25)
goto_168_64()
t1.setheading(180)
t2.setheading(0)
for x in range(23):
t1.forward(2)
t2.forward(2)
t1.right(4)
t2.left(4)
t1.setheading(90)
t2.setheading(90)
t1.forward(10)
t2.forward(10)
t1.setheading(180)
t2.setheading(0)
t1.forward(140)
t2.forward(140)
t1.penup()
t2.penup()
t1.goto(0,103)
t2.goto(0,103)
t1.pendown()
t2.pendown()
t1.goto(0,93)
t2.goto(0,93)
t1.end_fill()
t2.end_fill()
background()
draw()
turtle.mainloop()
Here is a picture of the output:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我们将其视为单个多边形,您可能可以用更少的一只乌龟和十几行代码来获得您想要的东西:
您可以通过使用变量 (或变量)用于相关绘图方向并在循环中重复一半代码。
You might be able to get what you want with one less turtle and a dozen fewer lines of code if we think of this as a single polygon:
You might be able to reduce the above code further by using a variable (or variables) for the relative drawing direction and repeating half the code in loop.