Draw a boat using Python Turtle

Draw a boat using Python Turtle

Introduction

Hello friends, welcome to copyassignment.com. Our topic for today is to draw a simple boat using python turtle module. A very simple topic and easy to draw using a python turtle. Each line of code explains thoroughly the object we draw. The comments help in the documentation and easy understanding of the topic

We will go through the code step by step:

Import Turtle

import turtle
t=turtle.Turtle()
scr=turtle.Screen()
scr.bgcolor("SkyBlue1")

Import is the function that imports or gets the modules or packages which we use in our projects. So in our project, we have imported the turtle module to access its functions.

Set the t as the turtle object. We have set the background color of the screen as Skyblue.

Draw a boat shape using Python turtle functions

t.color("black","orange")
t.penup()
t.goto(-100,-150)
t.begin_fill()
t.pendown()
t.forward(200)
t.left(60)
t.forward(80)
t.setheading(180)
t.forward(280)
t.left(120)
t.forward(80)
t.end_fill()
t.backward(80)
t.setheading(0)
t.forward(140)
t.left(90)

We have set the pen colour to black and the color of the boat to orange. We have set the turtle position to goto(-100,-150). This is the starting position of our boat. The forward()function to move the turtle forward the number of steps provided, left() and right()provides the angle of the turtle. The setheading() function sets the direction of the turtle points.

Draw the stick of the boat

#Draw the stick of the boat
t.pensize(8)
t.forward(125)
t.backward(5)
t.penup()

Here we have kept the pensize 8 to draw a broad stick over the boat.

Draw the white wings of the boat

#draw the white left wings of the boat
t.pensize(2)
t.pendown()
t.left(130)
t.forward(4)
t.color("white")
t.begin_fill()
t.forward(165)
t.setheading(0)
t.forward(125)
t.end_fill()
t.penup()
t.left(90)
t.forward(108)
t.right(90)
t.forward(7)

#draw the right white wing of the boat
t.pensize(2)
t.pendown()
t.right(40)
t.color("white")
t.begin_fill()
t.forward(168)
t.setheading(180)
t.forward(125)
t.end_fill()
t.penup()

Draw the three small Circle

Draw the three small circles of the boat
t.color("black","white")
t.goto(-70,-100)#Position of first circle
t.pendown()
t.begin_fill()
t.circle(10)
t.end_fill()
t.penup()
t.goto(-0,-100) #Position of second circle
t.pendown()
t.begin_fill()
t.circle(10)
t.end_fill()
t.penup()
t.goto(70,-100) #Position of third circle
t.pendown()
t.begin_fill()
t.circle(10)
t.end_fill()
t.penup()

In this part of the code, we have drawn 3 circles of the boat. The position is set by using goto function. The circle radius is 10. The penup() function is used when we are not drawing anything on the screen and the pendown() function is used to restart drawing.

Draw the circle and sunrays

#draw the circle of the sun
t.color("yellow","yellow")
t.goto(-200,200)
t.pendown()
t.begin_fill()
t.circle(30)
t.end_fill()
t.penup()

#sunrays
t.pensize(5)
t.goto(-200,170)
for i in range(12):
    t.pendown()
    t.backward(80)
    t.forward(80)
    t.left(30)
t.penup()

Here we have drawn the sun whose radius is 30 and position is set to goto(-200,200). At position goto(-200,170)i.e y=200-170 is 30 steps backward of the sun position, we have started drawing the sunrays. For this, we have used the for loop function. It takes 12 iterations to complete the sunrays.

Draw the water for the boat using Python Turtle

#Draw the water 
t.goto(-800,-150)
t.setheading(0)
t.color("Blue","Blue")
t.pendown()
t.begin_fill()
t.forward(1500)
t.right(90)
t.forward(180)
t.right(90)
t.forward(1500)
t.end_fill()
turtle.done()

This code defines the water for the boat. The setheading(0) points to the east and the position is set to goto(-800,-150) to draw the boat. The turtle.done() is an important function as it specifies smooth exit and completion of the program.

Complete Code to draw a boat using Python Turtle

#import Turtle
import turtle

t=turtle.Turtle()
scr=turtle.Screen()
scr.bgcolor("SkyBlue1")#Background Color

#Draw the deck of the boat
t.color("black","orange")
t.penup()
t.goto(-100,-150)
t.begin_fill()
t.pendown()
t.forward(200)
t.left(60)
t.forward(80)
t.setheading(180)
t.forward(280)
t.left(120)
t.forward(80)
t.end_fill()
t.backward(80)
t.setheading(0)
t.forward(140)
t.left(90)

#Draw the stick of the boat
t.pensize(8)
t.forward(125)
t.backward(5)
t.penup()

#draw the white left wings of the boat
t.pensize(2)
t.pendown()
t.left(130)
t.forward(4)
t.color("white")
t.begin_fill()
t.forward(165)
t.setheading(0)
t.forward(125)
t.end_fill()
t.penup()
t.left(90)
t.forward(108)
t.right(90)
t.forward(7)

#draw the right white wing of the boat
t.pensize(2)
t.pendown()
t.right(40)
t.color("white")
t.begin_fill()
t.forward(168)
t.setheading(180)
t.forward(125)
t.end_fill()
t.penup()

#Draw the three small circles of the boat
t.color("black","white")
t.goto(-70,-100)
t.pendown()
t.begin_fill()
t.circle(10)
t.end_fill()
t.penup()
t.goto(-0,-100)
t.pendown()
t.begin_fill()
t.circle(10)
t.end_fill()
t.penup()
t.goto(70,-100)
t.pendown()
t.begin_fill()
t.circle(10)
t.end_fill()
t.penup()

#draw the circle of the sun
t.color("yellow","yellow")
t.goto(-200,200)
t.pendown()
t.begin_fill()
t.circle(30)
t.end_fill()
t.penup()

#sunrays
t.pensize(5)
t.goto(-200,170)
for i in range(12):
    t.pendown()
    t.backward(80)
    t.forward(80)
    t.left(30)
t.penup()

#Draw the water
t.goto(-800,-150)
t.setheading(0)
t.color("Blue","Blue")
t.pendown()
t.begin_fill()
t.forward(1500)
t.right(90)
t.forward(180)
t.right(90)
t.forward(1500)
t.end_fill()
turtle.done()

Output

Output of Boat using Python Turtle
A boat using Python Turtle

This is the output of our boat we have completed successfully drawing. Please leave your comments in the comment box and keep reading more articles.


Also Read:

 

Share:
Avatar of divesh mandhyan

Author: divesh mandhyan