2015-04-03 213 views

回答

1

尝试以下操作:

import turtle 
t = turtle.Pen() 
t.left(90) 
for x in range(180): 
    t.forward(1) 
    t.right(1) 
t.right(90) 
t.forward(115) 
+0

你是怎么想出118直径的?因为乌龟每次向前移动1次,我预计直径为360周长/ math.pi,它接近于115,这很好 - - 118过冲(如果你隐藏乌龟本身) – cdlane 2017-04-26 16:48:43

+0

我不知道@cdlane。这是2年前。我将编辑为115. – 2017-04-30 16:01:22

13

Python turtle reference上一圈。 例如,对于一个半圈半径为100这将是:

import turtle 
turtle.circle(100,180) 
+2

这应该是公认的答案 – 2016-03-06 20:48:08

0

你也可以这样做只是用一圈。 turtle.circle(半径,范围,步骤)例如。 turtle.circle(50180) - 一步是可选的(

0

为了完整起见,一种方法来创建与使用龟冲压而不是绘制半圆:

from turtle import Turtle, Screen 

screen = Screen() 

DIAMETER = 200 
STAMP_SIZE = 20 
BACKGROUND = screen.bgcolor() 

yertle = Turtle('circle', visible=False) 
yertle.penup() 

yertle.shapesize(DIAMETER/STAMP_SIZE) 
yertle.color('black', BACKGROUND) # drop second argument for a filled semicircle 
yertle.stamp() 

yertle.shape('square') 
yertle.shapesize(stretch_len=(DIAMETER/2)/STAMP_SIZE) 
yertle.color(BACKGROUND) 
yertle.forward(DIAMETER/4) 
yertle.stamp() 

screen.exitonclick() 

它有明显的缺点,但有时这正是你所需要的