-1

I'm using Turtle Graphics, and i want to draw a pixel at specific x,y position

something like :

pixel = turtle.Turtle()
pixel.draw(x, y)

Is it possible ?

Zahreddine Laidi
  • 560
  • 1
  • 7
  • 20

1 Answers1

1
  • The goto, setpos and setposition methods of the turtle module can be used to set the position to a given x, y for the turtle.

  • Then, the dot method can be used to draw a pixel at the point.


# STEP-1: GOING TO (X, Y)
# Any one of these methods can be used
# pixel.goto(x, y) # or
# pixel.setpos(x, y) # or
pixel.setposition(x, y)

# STEP-2: DRAWING A PIXEL
pixel.dot(1, "black") # drawing the pixel.

Further, a function can be defined incase the same has to be used multiple times like so -:

def draw_pixel(turtle, x, y, color) :
    # Draws a pixel of given color using given turtle at (x, y)
    
    # Any one of these methods can be used
    # turtle.goto(x, y) # or
    # turtle.setpos(x, y) # or
    turtle.setposition(x, y)
    turtle.dot(1, color) # drawing the pixel.
    return
typedecker
  • 1,351
  • 2
  • 13
  • 25