- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to draw different shapes using the Python Turtle library?
In this program, we will draw different shapes using the Turtle library in Python. Turtle is a python feature like a drawing board, which lets you command a turtle to draw all over it. The different shapes that we are going to draw are square, rectangle, circle and a hexagon.
Step 1: Take lengths of side for different shapes as input.
Step 2: Use different turtle methods like forward() and left() for drawing different shapes.
import turtle t = turtle.Turtle() #SQUARE side = int(input("Length of side: ")) for i in range(4): t.forward(side) t.left(90) #RECTANGLE side_a = int(input("Length of side a: ")) side_b = int(input("Length of side b: ")) t.forward(side_a) t.left(90) t.forward(side_b) t.left(90) t.forward(side_a) t.left(90) t.forward(side_b) t.left(90) #CIRCLE radius = int(input("Radius of circle: ")) t.circle(radius) #HEXAGON for i in range(6): t.forward(side) t.left(300)
SQUARE: Length of side: 100 RECTANGLE: Length of side a: 100 Length of side b: 20 CIRCLE: Radius of circle: 60 HEXAGON:Length of side: 100
- How to draw geometrical shapes on image using OpenCV Java Library?
- How to draw shapes using SVG in HTML5?
- Turtle graphics using Python
- How to draw custom shapes in JavaFX using the Path class?
- Draw geometric shapes on images using Python OpenCv module
- How to draw Image Contours using Java OpenCV library?
- How to connect different AWS services using Boto3 library in Python?
- How to create different shapes with CSS?
- Python - Drawing different shapes on PyGame window
- Turtle programming in Python
- How to draw markers on an image using Java OpenCV library?
- What are the different shapes of galaxies?
- How can Bokeh be used to visualize different shapes of data points in Python?
- How to access and convert time using the time library in Python
- Multiply arguments element-wise with different shapes in Numpy