10

How to draw a semi circle(half circle) in python turtle only?

I can only use Python turtle. I have try looking for resouces but no luck on finding ones that only use Python turtle.

cdlane
  • 40,441
  • 5
  • 32
  • 81
BobTheCat
  • 127
  • 2
  • 2
  • 8

6 Answers6

23

See Python turtle reference on circle. For example, for a semi-circle with radius 100 it would be:

import turtle
turtle.circle(100,180)
nare
  • 231
  • 2
  • 5
2

Try the following:

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)
Luke Taylor
  • 8,631
  • 8
  • 54
  • 92
  • How did you come up with the 118 diameter? Since the turtle moves forward 1 each time, I'd expect a diameter of 360 circumference / math.pi which is closer to 115 which works fine -- 118 overshoots (if you hide the turtle itself.) – cdlane Apr 26 '17 at 16:48
  • I have no idea @cdlane. It was 2 years ago. I'll edit to 115. – Luke Taylor Apr 30 '17 at 16:01
1

you can also do it just using circle. turtle.circle(radius, extent,steps) eg.

turtle.circle(50,180) # - step is optional 
math scat
  • 310
  • 8
  • 17
user1113186
  • 65
  • 1
  • 2
  • 8
0

For completeness, a way to create a semicircle with turtle using stamping instead of drawing:

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()

It has its obvious shortcomings but sometimes it's exactly what you need.

cdlane
  • 40,441
  • 5
  • 32
  • 81
0

for drawing a semicircle in python turtle is very simple all you have to do is

import turtle
tom=turtle.Turtle()
tom.circle(100,180)

for the circle, the first digit is the radius of the circle and the second one is the amount that you want to draw it for a semicircle you can use 180 degrees as shown in the code above but you can do a quarter of a circle then if you want to connect the semicircle just turn left then for forward the radius*2

Community
  • 1
  • 1
Arsham
  • 141
  • 1
  • 9
0

If You also want a line under the semicircle(like a moon), Try this

import turtle
turtle.circle(100, 180) #Draws a circle with 180 degrees and 100 pixels radius(a half circle)
turtle.left(90)
turtle.forward(200)
math scat
  • 310
  • 8
  • 17