...

Soccer Field

In this class, students will learn how to draw a soccet field using the Turtle graphics library. Through this project, students will have the opportunity understand how to create a reusable function to draw a rectangle and use it in multiple occasions.
The lesson will cover the following topics:


  •     Introduction to the Turtle graphics library
  •     Understanding the For loop
Step 1: Let's start coding
  • In your logged-in trinket account click on New Trinket -> Python

  • Or Open the blank Python template trinket: Open New.
  • Next
    Step 2: Draw a Soccer Field

    Create a window

    The first step is to import the Turtle module. Place import statements at the top of your code. Next, define the screen and specify its dimension and set the background colour. done() command must be the last statement in a turtle graphics program. Type the code as follows:

    Create a function to draw a rectangle

    We define a function named rectangle that takes four parameters:x, y, w, and h. These parameters represent the x and y coordinates of the bottom-left corner of the rectangle, as well as its width w and height h. The function's purpose is to draw a rectangle starting from the specified coordinates and with the specified dimensions.

    Draw the Grass Stripes

    We will use a for loop to draw a total of 8 grass stripes. We'll start at the initial position x and y (which represent the bottom-left corner of the first stripe), and we'll draw a rectangle for each stripe using the rectangle function. After each stripe, we'll move the starting position x by 50 pixels to the right to create the next stripe.

    Draw the Field boundary

    This part of the code is responsible for drawing the outer boundary lines of the soccer field. It uses the rectangle function that we defined earlier to draw a rectangle that outlines the entire field.

    Draw the Middle line and circle

    Draw the middle line using the goto functions. After drawing the middle line, add the following code to draw a circle at the centre of the field:

    Draw the Goal Boxes

    Add a text message

    The write function to display the text message "GO MATILDAS!" on the screen.

  • The text is written using the font Comic Sans MS with a font size of 30 and a normal font style.
  • The align="center" argument centers the text horizontally at the specified position.
  • Prev Next
    Step 3: The complete code
    Step 4: Save your work

  • If you don't have a Trinket account, click the down arrow and then click Link. This will give you a link that you can save and come back to later.
  • If you have a Trinket account, you can click Remix to save your own copy of the trinket.
  • Prev Next
    Complete and Share

    Submit your final project



    Copy your Trinket Url

  • Click Share->Link
  • Copy the link to share your code
  • Paste link into the field
  • Prev