如何获取乌龟图形乌龟的X坐标 [英] How do I get the X coordinate for my turtle graphics turtle
本文介绍了如何获取乌龟图形乌龟的X坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以使用以下代码创建一个将在窗口中的乌龟:
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);
但是当我有2只海龟,t1和t2时,我不知道如果我该怎么办想知道turtle1的X坐标。
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);
如果我要写 int getX(w)
,我会得到哪些海龟X坐标?我如何写,所以我得到 t1
s cordinate?
If I were to write int getX(w)
, which turtles X coordinate would I get? How do I write so I get t1
s cordinate?
推荐答案
我不知道你正在使用什么Turtle类,但我想你会做这样的事情:
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);
这篇关于如何获取乌龟图形乌龟的X坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文