3

How do you draw an ellipse/oval in turtle graphics in Python? I want to be able to draw an ellipse and part of an ellipse using the circle() function or similar. I can stamp one using

turtlesize(stretch_wid=None, stretch_len=10, outline=None)

But I don't want it to be color filled.

ggorlen
  • 44,755
  • 7
  • 76
  • 106
Tristan
  • 33
  • 1
  • 1
  • 3

3 Answers3

8

I made my own function for drawing ovals that I personally think is very useful:

def talloval(r):               # Verticle Oval
    turtle.left(45)
    for loop in range(2):      # Draws 2 halves of ellipse
        turtle.circle(r,90)    # Long curved part
        turtle.circle(r/2,90)  # Short curved part

def flatoval(r):               # Horizontal Oval
    turtle.right(45)
    for loop in range(2):
        turtle.circle(r,90)
        turtle.circle(r/2,90)

The r is the radius of the circle and it controls how big the ellipse is. The reason for the turn left/right is because without it, the ellipse is diagonal.

sjaustirni
  • 3,056
  • 7
  • 32
  • 50
Ollie
  • 81
  • 1
  • 2
4

We can make an ellipse using its parametric equation in Turtle module. The code below might be a bit long but using this we can draw the ellipse in any orientation as required.You can edit it according to the requirement.We are basically changing the parametric angle of ellipse and plotting the curve.

  import turtle
  import math
  def ellipse(a, b, h=None, k=None, angle=None, angle_unit=None):
     myturtle = turtle.Turtle()
     if h is None:
       h = 0
     if k is None:
       k = 0
    # Angle unit can be degree or radian
     if angle is None:
       angle = 360
       converted_angle = angle*0.875
     if angle_unit == 'd' or angle_unit is None:
       converted_angle = angle * 0.875
     # We are multiplying by 0.875 because for making a complete ellipse we are plotting 315 pts according
     # to our parametric angle value
     elif angle_unit == "r":
       converted_angle = (angle * 0.875 * (180/math.pi))
     # Converting radian to degrees.
    for i in range(int(converted_angle)+1):
       if i == 0:
         myturtle.up()
       else:
         myturtle.down()
       myturtle.setposition(h+a*math.cos(i/50), k+b*math.sin(i/50))
   turtle.done()
0

You can use shapesize() function of turtle to make an ellipse.

shape("circle")
shapesize(5,4,1)
fillcolor("white")
avinash pandey
  • 1,321
  • 2
  • 11
  • 15
  • Hey, thanks for your reply, there is no shape named "ellipse", however your fillcolor("white") command worked for the #turtlesize(stretch_wid=None, stretch_len=10, outline=None) I mentioned above. So you helped me solve it! :) – Tristan Apr 06 '15 at 05:33
  • This example is deceiving. The shape function sets the shape of the turtle, i.e. the indicator of the drawing point. So yes, you can make the turtle look like an oval, but any future drawing will move your oval to a new position. – Mr. Lee Nov 19 '22 at 22:02
  • @Mr.Lee you can use the turtle method stamp() to make it permanent – user2757572 Apr 10 '23 at 08:49