turtle.towards() function in Python
Last Updated :
26 Jul, 2020
The turtle module provides turtle graphics primitives, in both object-oriented and procedure-oriented ways. Because it uses tkinter for the underlying graphics, it needs a version of Python installed with Tk support.
turtle.towards()
This function is used to return the angle, between the line from turtle-position to the position specified by x, y, and the turtle’s start orientation.
Syntax :
turtle.towards(x, y=None)
Parameters:
Arguments |
Description |
x |
a number or a pair/vector of numbers or a turtle instance |
y |
a number or None or None |
Below is the implementation of the above method with an example :
Python3
import turtle
ang = turtle.towards( 100 , 0 )
print (ang)
ang = turtle.towards( 0 , 100 )
print (ang)
ang = turtle.towards( - 100 , 0 )
print (ang)
ang = turtle.towards( 0 , - 100 )
print (ang)
|
Output :
0.0
90.0
180.0
270.0
Here we can see that one can easily get an angle towards any coordinate point without going to that point. In the above example turtle remain on (0,0) i.e. home and get all angles to the specified position without any movement.