Return the angle of the line from the turtle's position to (x, y). Arguments: x -- a number or a pair/vector of numbers or a turtle instance y -- a number None None call: distance(x, y) # two coordinates --or:
(self, x, y=None)
| 1926 | return abs(pos - self._position) |
| 1927 | |
| 1928 | def towards(self, x, y=None): |
| 1929 | """Return the angle of the line from the turtle's position to (x, y). |
| 1930 | |
| 1931 | Arguments: |
| 1932 | x -- a number or a pair/vector of numbers or a turtle instance |
| 1933 | y -- a number None None |
| 1934 | |
| 1935 | call: distance(x, y) # two coordinates |
| 1936 | --or: distance((x, y)) # a pair (tuple) of coordinates |
| 1937 | --or: distance(vec) # e.g. as returned by pos() |
| 1938 | --or: distance(mypen) # where mypen is another turtle |
| 1939 | |
| 1940 | Return the angle, between the line from turtle-position to position |
| 1941 | specified by x, y and the turtle's start orientation. (Depends on |
| 1942 | modes - "standard" or "logo") |
| 1943 | |
| 1944 | Example (for a Turtle instance named turtle): |
| 1945 | >>> turtle.pos() |
| 1946 | (10.00, 10.00) |
| 1947 | >>> turtle.towards(0,0) |
| 1948 | 225.0 |
| 1949 | """ |
| 1950 | if y is not None: |
| 1951 | pos = Vec2D(x, y) |
| 1952 | if isinstance(x, Vec2D): |
| 1953 | pos = x |
| 1954 | elif isinstance(x, tuple): |
| 1955 | pos = Vec2D(*x) |
| 1956 | elif isinstance(x, TNavigator): |
| 1957 | pos = x._position |
| 1958 | x, y = pos - self._position |
| 1959 | result = round(math.degrees(math.atan2(y, x)), 10) % 360.0 |
| 1960 | result /= self._degreesPerAU |
| 1961 | return (self._angleOffset + self._angleOrient*result) % self._fullcircle |
| 1962 | |
| 1963 | def heading(self): |
| 1964 | """ Return the turtle's current heading. |