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 turtle
- Make turtle
- Define a function to draw a square with dots
- Call that function
- Hide the turtle.
Below is the implementation :
Python3
import turtle
pen = turtle.Turtle()
def draw(space,x):
for i in range (x):
for j in range (x):
pen.dot()
pen.forward(space)
pen.backward(space * x)
pen.right( 90 )
pen.forward(space)
pen.left( 90 )
pen.penup()
draw( 10 , 8 )
pen.hideturtle()
|
Output :
2) Draw Dot Rectangle
Following steps are used :
- Import turtle
- Make turtle
- Define a function to draw a rectangle with dots
- Call that function
- Hide the turtle.
Below is the implementation :
Python3
import turtle
pen = turtle.Turtle()
def draw(space,x,y):
for i in range (x):
for j in range (y):
pen.dot()
pen.forward(space)
pen.backward(space * y)
pen.right( 90 )
pen.forward(space)
pen.left( 90 )
pen.penup()
draw( 10 , 5 , 12 )
pen.hideturtle()
|
Output :
3) Draw Dot Diamond:
Following steps are used :
- Import turtle
- Make turtle
- Define a function to draw a diamond with dots
- Call that function
- Hide the turtle.
Below is the implementation :
Python3
import turtle
pen = turtle.Turtle()
def draw(space,x):
for i in range (x):
for j in range (x):
pen.dot()
pen.forward(space)
pen.backward(space * x)
pen.right( 90 )
pen.forward(space)
pen.left( 90 )
pen.penup()
pen.left( 45 )
draw( 10 , 8 )
pen.hideturtle()
|
Output :
Last Updated :
10 Jul, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...