Gregor.
I am convinced by your argument about the non-elementary nature of
turtle.towards. I don't think I've ever used this function (or even
heard of it until you mentioned it!), but it's easy to believe it has
many uses. So I think it's worth adding.
However, I am not sure if the particular implementation you give for
towards works in the most natural way. My first reaction is that
turtle.towards(x,y) ought to make the turtle turn in-place so that it
points towards (x, y). Your implementation returns an angle, which, to
me, seems a little more complicated, and somewhat at odds with the
directness of turtle commands.
In your demo code towards(x, y) is always called inside setheading,
and I can't think of any common case where I would want to call
towards(x, y) without also wanting to set this direction to be the new
heading. So, I would suggest a change like this:
def toward(self, *args):
self.setheading(self._towards(*args))
def _towards(self, *args):
"""returns the angle, which corresponds to the line
from turtle-position to point (x,y).
Argument can be two coordinates or one pair of coordinates
or a RawPen/Pen instance.
"""
if len(args) == 2:
x, y = args
else:
arg = args[0]
if isinstance(arg, RawPen):
x, y = arg.position()
else:
x, y = arg
x0, y0 = self.position()
dx = x - x0
dy = y - y0
return (atan2(dy,dx) / self._invradian) % self._fullcircle
Toby
> I've - as a proposition - added one function to turtlenew:
> towards(*args), which returns the angle between the line from the turtle
> to the arg and the positive x-axis-direction. As a demo it's used
> in demo.py. (The idea is of course taken from Logo, where it is also
> present) This method uses atan2. So it's not elementary and young
> students won't be able to program it on their own. So I consider it
> rather essential. (In fact I incorporated it also into my book-specific
> turtle.py three years ago - which was also a moderate extension of the
> original one.)
--
Dr. Toby Donaldson
School of Computing Science
Simon Fraser University (Surrey)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"edupython" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/edupython
-~----------~----~----~----~------~----~------~--~---