Open In App

Python – Draw Octagonal shape Using Turtle Graphics

Last Updated : 19 Oct, 2020
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

In this article, we will learn how to Make an Octagon using Turtle Graphics in Python. For that lets first know what is Turtle Graphics.

Turtle graphics

  • backward(length): moves the pen in the backward direction by x unit.
  • right(angle): rotate the pen in the clockwise direction by an angle x.
  • left(angle): rotate the pen in the anticlockwise direction by an angle x.
  • penup(): stop drawing of the turtle pen.
  • pendown(): start drawing of the turtle pen.

 

Approach

  • Import the turtle modules.
  • Get a screen to draw on
  • Define an instance for the turtle.
  • For a drawing, an Octagon executes a loop 8 times.
  • In every iteration move the turtle 100 units forward and move it left 45 degrees( corresponding to 135 degrees between two sides, so 180-135=45 degrees).
  • This will make up an angle of 135 degrees between 2 sides.
  • 8 iterations will make up an Octagon perfectly. 
    Below is the Python implementation of the above approach:

Python3




# import for turtle module
import turtle
 
# making a workScreen
ws = turtle.Screen()
 
# defining a turtle instance
geekyTurtle = turtle.Turtle()
 
# iterating the loop 8 times
for i in range(8):
   
    # moving turtle 100 units forward
    geekyTurtle.forward(100)
     
    # turning turtle 45 degrees so
    # as to make perfect angle for an octagon
    geekyTurtle.left(45)


Output:

Octagon



Next Article

Similar Reads

Draw Shape inside Shape in Python Using Turtle
Prerequisites: Turtle Programming in Python Turtle is a Python feature like a drawing board, which let us command a turtle to draw all over it! We can use many turtle functions which can move the turtle around. Turtle comes in the turtle library. The turtle module can be used in both object-oriented and procedure-oriented ways. Some of the commonly
3 min read
Draw Diamond shape using Turtle graphics in Python
In this article, we are going to learn how to draw the shape of a Diamond using turtle graphics in Python. Turtle graphics: forward(length): moves the pen in the forward direction by x unit.right(angle): rotate the pen in the clockwise direction by an angle x.left(angle): rotate the pen in the anticlockwise direction by an angle x. Approach: Import
2 min read
Turtle Race Game Using Python - Turtle Graphics Library
Turtle graphics is a popular way to introduce programming concepts to beginners. It's a fun and interactive module in Python that lets you create simple drawings and animations using a "turtle" that moves around the screen. In this tutorial, we'll create an exciting turtle race game where you can bet on the color of a turtle and watch as they race
4 min read
Python - Draw Hexagon Using Turtle Graphics
In this article, we will learn how to make a Hexagon using Turtle Graphics in Python. For that lets first know what is Turtle Graphics. Turtle graphics Turtle is a Python feature like a drawing board, which let us command a turtle to draw all over it! We can use many turtle functions which can move the turtle around. Turtle comes in the turtle libr
2 min read
Python - Draw Star Using Turtle Graphics
In this article, we will learn how to make a Star using Turtle Graphics in Python. For that let's first know what is Turtle Graphics. Turtle graphics Turtle is a Python feature like a drawing board, which let us command a turtle to draw all over it! We can use many turtle functions which can move the turtle around. Turtle comes into the turtle libr
2 min read
Draw Panda Using Turtle Graphics in Python
Turtle is an inbuilt module in Python. It provides: Drawing using a screen (cardboard).Turtle (pen). To draw something on the screen, we need to move the turtle (pen), and to move the turtle, there are some functions like the forward(), backward(), etc. Prerequisite: Turtle Programming Basics Draw Panda Using Turtle Graphics In this section, we wil
2 min read
Draw Heart Using Turtle Graphics in Python
Turtle is an inbuilt module in Python. It provides: Drawing using a screen (cardboard).Turtle (pen). To draw something on the screen, we need to move the turtle (pen) and to move the turtle, there are some functions like the forward(), backward(), etc Prerequisite: Turtle Programming Basics Draw Heart Using Turtle Graphics In this section, we will
2 min read
Draw Rainbow using Turtle Graphics in Python
Turtle is an inbuilt module in Python. It provides: Drawing using a screen (cardboard).Turtle (pen). To draw something on the screen, we need to move the turtle (pen), and to move the turtle, there are some functions like the forward(), backward(), etc. Prerequisite: Turtle Programming Basics Draw Rainbow Using Turtle Graphics In this section, we w
2 min read
Draw Spiralling Circles Using Turtle Graphics in Python
Turtle is an inbuilt module of python. It enables us to draw any drawing by a turtle, methods defined in the turtle module, and by using some logical loops. To draw something on the screen(cardboard) just move the turtle(pen). To move turtle(pen) there are some functions i.e forward(), backward(), etc. Approach: Import and create a turtle instance.
1 min read
Draw Colorful Spiral Web Using Turtle Graphics in Python
Prerequisite: Turtle Basics “Turtle” is a Python feature like a drawing board, which lets us command a turtle to draw all over it. This comes packed with the standard Python package and need not be installed externally. Methods used: forward(value): moves the turtle in the forward direction.turtle.Pen(): setup the turtle penspeed(value): changes th
1 min read
Python - Draw "GFG" logo using Turtle Graphics
Prerequisites: Turtle Programming in Python Turtle is a Python feature like a drawing board, which let us command a turtle to draw all over it! We can use many turtle functions which can move the turtle around. Turtle comes into the turtle library. The turtle module can be used in both object-oriented and procedure-oriented ways. Some of the common
2 min read
turtle.shape() function in Python
The turtle module provides turtle graphics primitives, in both object-oriented and procedure-oriented ways. Because it uses tkinter for the underlying graphics, it needs a version of Python installed with Tk support. turtle.shape() This function is used to set the turtle shape to shape with a given name or, if the name is not given, return the name
1 min read
Draw a rectangular shape and extract objects using Python's OpenCV
OpenCV is an open-source computer vision and machine learning software library. Various image processing operations such as manipulating images and applying tons of filters can be done with the help of it. It is broadly used in Object detection, Face Detection, and other Image processing tasks. Let's see how to draw rectangular shape on image and e
4 min read
turtle.forward() method in Python-Turtle
The turtle module provides turtle graphics primitives, in both object-oriented and procedure-oriented ways. Because it uses Tkinter for the underlying graphics, it needs a version of Python installed with Tk support. turtle.forward() The turtle.forward() method is used to move the turtle forward by the value of the argument that it takes. It gives
1 min read
turtle.setpos() and turtle.goto() functions in Python
The turtle module provides turtle graphics primitives, in both object-oriented and procedure-oriented ways. Because it uses Tkinter for the underlying graphics, it needs a version of Python installed with Tk support. turtle.setpos() This method is used to move the turtle to an absolute position. This method has Aliases: setpos, setposition, goto. S
1 min read
Draw Circle in Python using Turtle
Turtle is a Python feature like a drawing board, which lets us command a turtle to draw all over it! We can use functions like turtle.forward(…) and turtle.right(…) which can move the turtle around. Turtle is a beginner-friendly way to learn Python by running some basic commands and viewing the turtle do it graphically. It is like a drawing board t
3 min read
Draw a Hut using turtle module in Python
Turtle is a inbuilt module in Python, which has many functions like forward(), backward(), right() and left() etc. You can draw a hut on the screen just by using the turtle module in Python. In this article, we will create a hut using the turtle module. Approach: Import turtleSet the background color.Define a function to draw the front portion of t
2 min read
Draw a Tic Tac Toe Board using Python-Turtle
The Task Here is to Make a Tic Tac Toe board layout using Turtle Graphics in Python. For that lets first know what is Turtle Graphics. Turtle graphics In computer graphics, turtle graphics are vector graphics using a relative cursor upon a Cartesian plane. Turtle is drawing board like feature which let us to command a turtle and draw using it. Feat
2 min read
Draw Cube and Cuboid in Python using Turtle
Prerequisite: Turtle Programming Basics Turtle is an inbuilt module in Python. It provides drawing using a screen (cardboard) and turtle (pen). To draw something on the screen, we need to move the turtle (pen). To move the turtle, there are some functions i.e forward(), backward(), etc. Drawing Cube Following steps are used: First draw the front sq
2 min read
Draw Colored Solid Cube using Turtle in Python
Turtle is an inbuilt module in Python. It provides: Drawing using a screen (cardboard).Turtle (pen). To draw something on the screen, we need to move this turtle (pen) and to move the turtle(pen), there are some functions like the forward(), backward(), etc. Prerequisite: Turtle Programming Basics Drawing Colored Solid Cube In this section, we will
2 min read
Draw smiling face emoji using Turtle in Python
Prerequisite: Python Turtle Basics Turtle is an inbuilt module in Python. It provides drawing using a screen (cardboard) and turtle (pen). To draw something on the screen, we need to move the turtle. To move turtle, there are some functions i.e forward(), backward(), etc. In this article, we will see how to draw a smiling face emoji using the Turtl
2 min read
Draw Clock Design using Turtle in Python
Prerequisites: Turtle Programming in Python Turtle is an inbuilt module in Python. It provides drawing using a screen (cardboard) and turtle (pen). To draw something on the screen, we need to move the turtle (pen). To move turtle, there are some functions i.e forward(), backward(), etc. To draw Clock Design : Following steps are used : Import turtl
2 min read
Draw Concentric Circles with VIBGYOR Using Turtle in Python
Prerequisite: Turtle Programming Basics Turtle is an inbuilt module in Python. It provides drawing using a screen (cardboard) and turtle (pen). To draw something on the screen, we need to move the turtle (pen). To move turtle, there are some functions i.e forward(), backward(), etc. To draw Concentric VIBGYOR : Following steps are used : Importing
2 min read
Draw Ellipse Using Turtle in Python
Prerequisite: Turtle Programming Basics Turtle is an inbuilt module in Python. It provides drawing using a screen (cardboard) and turtle (pen). To draw something on the screen, we need to move the turtle (pen). To move turtle, there are some functions i.e forward(), backward(), etc. Approach: The following steps are used : Import turtleDivide the e
2 min read
Draw Graph Grid Using Turtle in Python
Prerequisite: Turtle Programming Basics Turtle is an inbuilt module in Python. It provides drawing using a screen (cardboard) and turtle (pen). To draw something on the screen, we need to move the turtle (pen). To move turtle, there are some functions i.e forward(), backward(), etc. Approach: Following steps are used : Import turtleSet screenMake t
2 min read
Draw Dot Patterns Using Turtle in Python
Prerequisite: Turtle Programming Basics Turtle is an inbuilt module in Python. It provides drawing using a screen (cardboard) and turtle (pen). To draw something on the screen, we need to move the turtle (pen). To move turtle, there are some functions i.e forward(), backward(), etc. 1) Draw Dot Square Following steps are used : Import turtleMake tu
2 min read
Draw Chess Board Using Turtle in Python
Prerequisite: Turtle Programming Basics Turtle is an inbuilt module in Python. It provides drawing using a screen (cardboard) and turtle (pen). To draw something on the screen, we need to move the turtle (pen). To move turtle, there are some functions i.e forward(), backward(), etc. For drawing Chess Board following steps are used : Import turtle a
2 min read
Draw Spiraling Star using Turtle in Python
Prerequisite: Python Turtle Basics Turtle is an inbuilt module of python. It enables us to draw any drawing by a turtle and methods defined in the turtle module and by using some logical loops. To draw something on the screen(cardboard) just move the turtle(pen).To move turtle(pen) there are some functions i.e forward(), backward(), etcApproach to
1 min read
Draw Spiraling Polygon using Turtle in Python
Prerequisite: Python Turtle Basic Turtle is an inbuilt module of python. It enables us to draw any drawing by a turtle, methods defined in the turtle module and by using some logical loops. To draw something on the screen(cardboard) just move the turtle(pen). To move turtle(pen) there are some functions i.e forward(), backward(), etc. Approach to d
1 min read
Draw Spiraling Square using Turtle in Python
Prerequisite: Python Turtle Basic Turtle is an inbuilt module of python. It enables us to draw any drawing by a turtle, methods defined in the turtle module and by using some logical loops. To draw something on the screen(cardboard) just move the turtle(pen). To move turtle(pen) there are some functions i.e forward(), backward(), etc. Approach to d
1 min read
Practice Tags :
  翻译: