How do I get the X coordinate for my turtle graphics turtle

后端 未结 3 1121
悲&欢浪女
悲&欢浪女 2021-01-24 13:17

I can create a turtle that will be in a window with the following code:

Turtle t1 = new Turtle(w,100,100);

If I want to know its coordinates, I

3条回答
  •  囚心锁ツ
    2021-01-24 13:55

    For python turtle module, get the x and y coordinates of the turtle use the getPosition method like this:

    import turtle
    import time
    alex = turtle.Turtle()
    alex_text = turtle.Turtle()
    alex_text.goto(alex.position()[0], alex.position()[1])
    alex_text.write("hello")
    time.sleep(1)
    

    turtle.position() - Return the turtle’s current location (x,y) (as a Vec2D vector).

    Read more about it here: https://docs.python.org/3.3/library/turtle.html#turtle.write

提交回复
热议问题