Turtle Graphics are incompatible with gmpy
casevh
casevh at gmail.com
Wed Aug 5 02:54:12 EDT 2009
On Aug 4, 10:49 pm, Mensanator <mensana... at aol.com> wrote:
> I hadn't noticed this before, but the overhaul of Turtle Graphics
> dating
> back to 2.6 has been broken as far as gmpy is concerned.
> The reason is that code in turtle.py was chabged from
>
> v2.5
> if self._drawing:
> if self._tracing:
> dx = float(x1 - x0)
> dy = float(y1 - y0)
> distance = hypot(dx, dy)
> nhops = int(distance)
>
> to
>
> v3.1
> if self._speed and screen._tracing == 1:
> diff = (end-start)
> diffsq = (diff[0]*screen.xscale)**2 + (diff[1]
> *screen.yscale)**2
> nhops = 1+int((diffsq**0.5)/(3*(1.1**self._speed)
> *self._speed))
>
> Unfortunately, that calculation of nhops is illegal if diffsq is
> an .mpf (gmpy
> floating point). Otherwise, you get
>
> Traceback (most recent call last):
> File "K:\user_python26\turtle\turtle_xy_Py3.py", line 95, in
> <module>
> tooter.goto(the_coord)
> File "C:\Python31\lib\turtle.py", line 1771, in goto
> self._goto(Vec2D(*x))
> File "C:\Python31\lib\turtle.py", line 3165, in _goto
> nhops = 1+int((diffsq**0.5)/(3*(1.1**self._speed)*self._speed))
> ValueError: mpq.pow fractional exponent, inexact-root
>
Warning: Completely untested fix ahead!
What happens if you change turtle.py to use
nhops=1+int((math.sqrt(diffsq)/(3*math.pow(1.1, self._speed)
*self._speed))
casevh
More information about the Python-list
mailing list