Draw Dot Patterns Using Turtle in Python

• Last Updated : 10 Jul, 2020

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 package and making objectimport turtle     pen = turtle.Turtle()  # method to draw square with dots# space --> distance between dots# x     --> side of squaredef draw(space,x):  for i in range(x):    for j in range(x):                # dot        pen.dot()                  # distance for another dot        pen.forward(space)    pen.backward(space*x)          # direction    pen.right(90)    pen.forward(space)    pen.left(90)  # Main Sectionpen.penup()draw(10,8)  # hide the turtlepen.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 package and making objectimport turtle     pen = turtle.Turtle()  # method to draw rectangle with dots# space --> distance between dots# x     --> height of rectangle# y     --> width of rectangledef draw(space,x,y):  for i in range(x):    for j in range(y):                # dot        pen.dot()                  # distance for another dot        pen.forward(space)    pen.backward(space*y)          # direction    pen.right(90)    pen.forward(space)    pen.left(90)  # Main Sectionpen.penup()draw(10,5,12)  # hide the turtlepen.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 package and making objectimport turtle     pen = turtle.Turtle()  # method to draw diamond with dots# space --> distance between dots# x     --> side of diamonddef draw(space,x):  for i in range(x):    for j in range(x):                  # dot        pen.dot()                  # distance for another dot        pen.forward(space)    pen.backward(space*x)          # direction    pen.right(90)    pen.forward(space)    pen.left(90)  # Main Sectionpen.penup()  # direction to form diamondpen.left(45)draw(10,8)  # hide the turtlepen.hideturtle()

Output : My Personal Notes arrow_drop_up