【问题标题】:What is the easiest method to draw this on the screen using turtle graphics?使用海龟图形在屏幕上绘制它的最简单方法是什么?
【发布时间】:2018-10-03 07:45:07
【问题描述】:

在屏幕上绘制包括颜色在内的最简单方法是什么?

【问题讨论】:

  • 关于Regular polygons 的维基百科文章可能会有所帮助——尤其是2.1 Angles 部分。
  • 比手动绘制所有线段更简单的方法是使用turtle.circle() 并指定少量步骤以使其绘制内接正多边形。

标签: python turtle-graphics


【解决方案1】:

这个问题不用代码很难回答,但是如果你知道彩色海龟叫什么,你可以使用:

[turtle name goes here].forward([distance])

向前移动给定的乌龟

[turtle name goes here].backward([distance])

向后移动

[turtle name goes here].right([degrees/radians])
[turtle name goes here].left([degrees/ radians])

让乌龟左右转

例如:

#names the turtle Angie
Angie = Turtle()
#changes the color of Angie
Angie.color("blue")
#moves angie forward
Angie.forward(100)

【讨论】:

    【解决方案2】:

    这应该可以,希望对您有所帮助! :-)

    def polygon(length, sides, color):
        turtle.color(color)
        turtle.begin_fill()
        for i in range(sides):
            turtle.forward(length)
            turtle.left(360.0/sides)
        turtle.end_fill()
        turtle.penup()
        turtle.forward(length*1.5)
        turtle.pendown()
    
    polygon(100, 6, "green")
    polygon(100, 3, "blue")
    polygon(100, 4, "red")
    

    【讨论】:

    • 在我的屏幕上,OP 的多边形似乎有黑色轮廓,所以我会使用 turtle.fillcolor(color) 而不是 turtle.color(color)
    猜你喜欢
    • 2016-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-02
    • 2018-05-30
    相关资源
    最近更新 更多