turtle.dot() function in Python

The turtle.dot() function in Python draws a filled circular dot at the turtle’s current position. The pen can be up or down.

Syntax: turtle.dot(size=None, *color)
Parameters: size – the diameter of the dot (if None, uses max(pensize+4, 2*pensize)); color – a colorstring or a numeric color tuple.

Let us see an example to implement the turtle.dot() function in Python:

Demo10.py

# turtle.dot() function in Python
# Code by Studyopedia

import turtle

window = turtle.Screen()
t = turtle.Turtle()

t.dot(20, "red")        # Draw a red dot with diameter 20
t.forward(50)
t.dot(30, "blue")       # Draw a blue dot with diameter 30

window.exitonclick()

The following is the output:

turtle.dot() in Python Turtle

In the above code, we followed the below steps:

  1. Import the module: import turtle loads Python’s turtle graphics library.
  2. Create the screen: window = turtle.Screen() opens the drawing window.
  3. Create the turtle: t = turtle.Turtle() makes the turtle (your pen).
  4. Draw red dot: t.dot(20, “red”) draws a filled red dot of diameter 20 pixels centered at the turtle’s current position; the turtle doesn’t move and pen state doesn’t matter.
  5. Move forward: t.forward(50) moves 50 units in the current direction, drawing a line because the pen is down by default.
  6. Draw blue dot: t.dot(30, “blue”) draws a filled blue dot of diameter 30 pixels at the new position; again, the turtle doesn’t move.
  7. Close on click: window.exitonclick() keeps the window open until you click inside it, then closes.

If you liked the tutorial, spread the word and share the link and our website, Studyopedia, with others.


For Videos, Join Our YouTube Channel: Join Now


Read More:

turtle.home() function in Python
turtle.speed() function in Python
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment