Python and Turtle Difficulty Level 2,python,Tutorial Tutorial: Drawing Ovals with Python Turtle

Tutorial: Drawing Ovals with Python Turtle

This tutorial is going to show how to draw a basic oval shape as shown below with Python Turtle.

Oval with Python Turtle

We are going to draw the red arc in the bottom first. Let’s lift up the pen and goto the left end point of the red arc and set the heading to -45 degrees and draw a circle of 200 radius with 90 degrees of extent. Since a circle has 360 degrees, extent of 90 degrees draws a quarter circle. The following is the code snippet for the process above.

turtle.up()
turtle.goto(-140,-75)
turtle.down()
turtle.seth(-45)
turtle.color('red')
turtle.circle(200,90)

After finishing this, the heading of the heading should have increased by 90 degrees. You can call print(turtle.heading()) function to verify this after the last line of the code above.

Now let’s continue to draw the blue arc on the right. Change the pencolor to ‘blue’ and draw a circle with radius half of size as the red arc and 90 degrees of extent. The following is the code snippet for drawing the blue arc.

turtle.color('blue')
turtle.circle(100,90)

After this, we can continue to draw another red arc and blue arc to finish the whole oval. The following is the complete code for drawing this oval.

import turtle

screen = turtle.Screen()
screen.setup(500,500)
screen.title("Oval with 4 Arcs - PythonTurtle.Academy")
turtle.speed(1)
turtle.shape('turtle')

turtle.up()
turtle.goto(-140,-75)
turtle.down()
turtle.seth(-45)
turtle.color('red')
turtle.circle(200,90)
turtle.color('blue')
turtle.circle(100,90)
turtle.color('red')
turtle.circle(200,90)
turtle.color('blue')
turtle.circle(100,90)

You may be curious about in knowing how to draw ovals of other sizes, shapes, and even degrees of tilt. The best solution is to create a function that can take these different settings as parameters. The following is the function to draw oval with parameters x,y specifying the starting location of oval to draw; big_radius, small_radius specifying the radii of two circles; tilt specifying the the degree of tilt.

import turtle

screen = turtle.Screen()
screen.setup(500,500)
screen.title("Oval with 4 Arcs - PythonTurtle.Academy")
turtle.speed(0)
turtle.hideturtle()

def draw_oval(x,y,big_radius,small_radius,tilt):
    turtle.up()
    turtle.goto(x,y)
    turtle.down()
    turtle.seth(-45+tilt)
    turtle.color('red')
    turtle.circle(big_radius,90)
    turtle.color('blue')
    turtle.circle(small_radius,90)
    turtle.color('red')
    turtle.circle(big_radius,90)
    turtle.color('blue')
    turtle.circle(small_radius,90)

draw_oval(-100,-100,100,50,90)
draw_oval(0,0,100,30,0)
draw_oval(0,-200,60,30,45)

Try to call this draw_oval function with different parameters. For the ones in the code snippet above it should draw something like this:

Ovals of Different Shapes, Degrees of Tilt, and Sizes

Related Tutorials:
How to Draw Egg Shapes
How to Draw Petal of Flower
How to Draw Crescent Moon
How to Draw Rounded Rectangles and Squares

Related Projects:

Related Post