Introduction
Hello friends, welcome to violet-cat-415996.hostingersite.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
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:
- Simple Code to compare Speed of Python, Java, and C++?
- Falling Stars Animation on Python.Hub October 2024
- Most Underrated Database Trick | Life-Saving SQL Command
- Python List Methods
- Top 5 Free HTML Resume Templates in 2024 | With Source Code
- How to See Connected Wi-Fi Passwords in Windows?
- 2023 Merry Christmas using Python Turtle
- 23 AI Tools You Won’t Believe are Free
- Python 3.12.1 is Now Available
- Best Deepfake Apps and Websites You Can Try for Fun
- Amazon launched free Prompt Engineering course: Enroll Now
- 10 GitHub Repositories to Master Machine Learning
- Hello World in 35 Programming Languages
- How to Scrape Data From Any Website with Python?
- Become Job Ready With Free Harvard Computer Science course: Enroll Now
- Free Python Certification course from Alison: Good for Resume
- Download 1000+ Projects, All B.Tech & Programming Notes, Job, Resume & Interview Guide, and More – Get Your Ultimate Programming Bundle!
- Udacity Giving Free Python Course: Here is how to Enroll
- Love Babbar’s Income Revealed
- Top 5 Websites to Learn Programming in 2024
- Python Internship for college students and freshers: Apply Here
- Microsoft Giving Free Python Course in 2023: Enroll Now
- Top 5 Free Python Courses on YouTube in 2024
- Complete Python Roadmap for Beginners in 2024
- New secrets to Earn money with Python in 2024
- Connect with HR Directly – Job Hack
- Google offering free Python course: Enroll Today
- What is an AI Tool?
- Google Internship 2024
- TCS Launched Free Certification Course with Industry Recognized Value