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

后端 未结 3 1122
悲&欢浪女
悲&欢浪女 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:37

    I have no idea what Turtle class you are using, but I'd imagine you'd do something like this:

    int x1 = t1.getX(w);
    int x2 = t2.getX(w);
    
    0 讨论(0)
  • 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

    0 讨论(0)
  • 2021-01-24 13:56

    Use turtle.xcor() it returns the x position. Use turtle.ycor() it returns the y position.

    0 讨论(0)
提交回复
热议问题