Drawing a Car using Python Turtle Module
The Logo programming language is frequently linked to turtle graphics. In the late 1960s, Seymour Papert added turtle graphics support to Logo to support his version of the turtle robot, which is a simple robot controlled from the user’s workstation and designed to carry out the drawing functions assigned to it using a small retractable pen set into or attached to the robot’s body.
The standard library of the Python programming language now contains a Turtle graphics module. Turtle in Python, like its Logo ancestor, allows programmers to manipulate one or more turtles in a two-dimensional space.
Overview of the syntax
A location, an orientation (or direction), and a pen are the three qualities of the turtle. Color, width, and on/off state are all properties of the pen (also called down and up).
“Move ahead 10 spaces” and “turn left 90 degrees” are orders that the turtle responds to based on its current location. The turtle’s pen can also be managed by enabling it, changing its color, and adjusting its breadth. By visualizing what they would do if they were the turtle, a pupil may comprehend (and forecast and reason about) the turtle’s motion. This is referred to as “body syntonic” reasoning by Seymour Papert.
import turtle // start of the program //body //of the main //code turtle.done() //end of the program
Inorder to understand the codes to draw various shapes given below, Getting Started with Powerful yet Easy Python Graphics Module, Turtle.
The principles governs everything in every subject. They’re the basis on which all incredible exploits are built. To execute acts that appear magical to us simple humans, great scientists and artists equally rely on their most basic skills. Same is the case for python turtle module.
In order to make any drawings in python turtle, for this instance a car, the fundamentals are mandatory. If you think about it a car is only a rectangle for body, circles for tyers and lines for the windows. Enough of explaining, let’s get coding!
The following is the code for drawing a car using python turtle module
import turtle TommyCar = turtle.Turtle() # code for drawing rectangular upper body TommyCar.color('black') TommyCar.fillcolor('red') TommyCar.penup() TommyCar.goto(0,0) TommyCar.pendown() TommyCar.begin_fill() TommyCar.forward(370) TommyCar.left(90) TommyCar.forward(50) TommyCar.left(90) TommyCar.forward(370) TommyCar.left(90) TommyCar.forward(50) TommyCar.end_fill() # code for drawing window and roof TommyCar.penup() TommyCar.goto(100, 50) TommyCar.pendown() TommyCar.setheading(45) TommyCar.forward(70) TommyCar.setheading(0) TommyCar.forward(100) TommyCar.setheading(-45) TommyCar.forward(70) TommyCar.setheading(90) TommyCar.penup() TommyCar.goto(200, 50) TommyCar.pendown() TommyCar.forward(49.50) # code for drawing two tyres TommyCar.penup() TommyCar.goto(100, -10) TommyCar.pendown() TommyCar.color('black') TommyCar.fillcolor('black') TommyCar.begin_fill() TommyCar.circle(20) TommyCar.end_fill() TommyCar.penup() TommyCar.goto(300, -10) TommyCar.pendown() TommyCar.color('black') TommyCar.fillcolor('black') TommyCar.begin_fill() TommyCar.circle(20) TommyCar.end_fill() TommyCar.hideturtle() turtle.done()
Although not a Ferrari, still we made a car using python turtle module.
From above code we can observe,
=> In order to represent a car, we’ll use the turtle module to generate several shapes.
=> The circle() function can be used to draw tyres.
=> The upper body is shaped like a rectangle.
=> The trapezoid shape of the roof and windows is comparable to that of a trapezoid.
=> A automobile will be created by overlapping all of the above shapes in specific positions.