...

Draw a Sailboat

As we will continue working with the Turtle graphics library, we'll learn how to draw using existing functions. As well as how to use a FOR loop for repetitive tasks.
As part of this project you will learn:

The Turtle library

What is FOR loop?

A for loop is used for iterating over a sequence or performing repetitive tasks.

With the for loop, we can execute a set of statements, once for each item in a list or as many times as indicated.

The range() Function

To loop through a set of code a specified number of times, we can use the range() function

This piece of code prints the same value 6 times

Next
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.

  • Prev Next
    Step 2: 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.
  • Add the background colour to the screen using screen.bgcolor("colourName") command.
  • Hide the cursor with hideturtle() command.
  • Don't forget done() command, it must be the last statement of your program.
  • Type the code as follows:

    Prev Next
    Step 3: Let's draw a water

    Now draw a rectangle and fill it with blue colour. It will represent water.
    We will use the following commands:

  • speed(number) - set the speed of your drawing from 1 to 10
  • penup() - get your writing pen up
  • pendown() - put your writing pen down
  • goto(x,y) - go to specific coordinate
  • color("colourName") - set the colour
  • begin_fill() and end_fill() - start and end of filling the object with the selected colour
  • forward(number) - move forward to the number of pixels
  • right(angle) and left(angle) - turn right or left on the specified angle

  • Type the code as follows:

    Prev Next
    Step 4:Draw the base of the boat and mast

  • First set the cursor at the starting position with goto() command
  • Select brown colour
  • Follow the code below to complete the drawing of the base
  • Similarly, we draw a mast, follow the code below
  • Prev Next
    Step 5: Draw the right and left sail

    Two white triangles will represent the right and left sail. Make sure you use right() or left() functions with the correct angle to draw a triangle

  • Move to the start point using goto() command
  • Select white colour using color("white")
  • Follow the code to draw the right and left sail
  • Prev Next
    Step 6: Finishing our drawing

    To finish up our sailboat drawing let's add a sun to the sky. To draw a sun we will use the circle command.

  • circle(radius) - This function draws a circle of the given radius by taking the current position as the centre.
  • Prev Next
    Step 7: 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
    Step 8: Challenge

    Optional: Add your own details to the drawing, you might want to improve the boat, add clouds or anything else.


    I am waiting to see your artwork!

    Prev Next
    Step 9: Complete and Share

    Submit your final project

    In order to receive your completion certificate all projects should be submited before 6th April 2023



    Copy your Trinket Url

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