尝试使用海龟绘制这张图片,只是卡在将正方形画成圆形的最后一点上。 squares to make circle 到目前为止,我已经尝试只画出每条线的点,但由于一些不一致而花费了很长时间。到目前为止我所拥有的是
def square(side_length):
for i in range(4):
turtle.fd(side_length)
turtle.lt(90)
square (150)
turtle.penup()
####New Square###
turtle.left(90)
turtle.forward(75)
turtle.left(90)
turtle.forward(30)
turtle.right(180)
turtle.right(45)
turtle.pendown()
def square(side_length):
for i in range(4):
turtle.fd(side_length)
turtle.lt(90)
square (150)
这会绘制两个正方形。现在我只需要找到一种方法将两个正方形顺时针旋转 30 度,旋转 4 次。是否有一个函数可以用来执行此操作,或者我只需要进行大量数学运算并计算即可绘制每条单独的线?
最佳答案
尽管有它的名字,turtle.circle
可用于绘制其他正多边形。它还可用于仅绘制多边形的一部分。结合上下提笔,您可以轻松绘制一系列共享同一中心的旋转形状。
例如,
for i in range(19):
turtle.circle(100, 360, 4) # draw a square
turtle.penup()
# "draw" 10 degrees of the same circle, with the pen up, just to move the pen
turtle.circle(100, 10, 4)
turtle.pendown()
(圆只是一个具有足够边数来近似圆的多边形。如果您没有显式指定第三个参数,turtle
将根据半径选择一个足够大的值。)
关于Python Turtle 用正方形绘制圆形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52486188/