Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 can write:

int getX(w);

But when I have 2 turtles, t1 and t2, I don't know what to do if I want to know turtle1's X coordinates.

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

If I were to write int getX(w), which turtles X coordinate would I get? How do I write so I get t1s cordinate?

like image 723
user2779497 Avatar asked Oct 25 '25 14:10

user2779497


1 Answers

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

like image 82
Ja S Avatar answered Oct 28 '25 03:10

Ja S