Kent Johnson schrieb:
On Tue, Aug 5, 2008 at 6:49 PM, Dick Moores <[EMAIL PROTECTED]> wrote:
For a while now I've had trouble with end_fill(). Sometimes I can use
it to fill a figure such as a square, triangle or rectangle, but
sometimes not.

Here's a barebones script using end_fill(). As you can see, it draws a
square twice, but fails to fill it. Pleas show me how to use it
correctly in tandem with begin_fill().

Hi all,

Kent's version below repairs the problem more or less accidentally
and moreover not completely:

(1) the first square is not filled properly; instead a filled pentagon appears
after the first traversal of the loop.
(2) the filling takes place due to the goto() call after the end_fill() call and
before the clear() call.

This is due to a bug in turtle.py - interestingly after so many years of use
and improvement of turtle.py there still appear new bugs from time to time.

The bug consists in a missing update of the Canvas in the fill() function
You can repair it by inserting a line at line#309 in turtle.py in the
fill method as follows:

       if self._filling:
           path = tuple(self._path)
           smooth = self._filling < 0
           if len(path) > 2:
               item = self._canvas._create('polygon', path,
                                           {'fill': self._color,
                                            'smooth': smooth})
               self._items.append(item)
               self._canvas.update()      #  <=== bug-fix
       self._path = []

Now for the good news:

(1) If you have done this, not only Dick's program works as
intended, but you may also write the square_filling program
in a cleaner way, for instance like this:

from turtle import *
import time

setup(width=1000, height=700, startx=0, starty=0)
color_name = 'red'
x, y = 50, 50
color(color_name)
print color_name
up()
goto(x, y)
down()
for n in range(2):
  begin_fill()
  goto(x, -y)
  goto(-x, -y)
  goto(-x, y)
  goto(x, y)
  end_fill()
  print "end_fill()"
  time.sleep(1)
  clear()

(2) Python 2.6 will have a new turtle module - formerly known to some
as xturtle.py - which has much more capabilities and which at least doesn't show this bug. Presumably there will appear others, especially in the beginning of
it's use. It is contained in Python2.6 beta2, it runs also under Python2.5
and it should be (nearly?) 100%-compatible with the old turtle module.

Its documentation can be found here:
http://docs.python.org/dev/library/turtle.html#module-turtle

It would be really very helpful, if those of you who use to use turtle
graphcis would work with this new module in order to reveal as many
bugs as possible before the final release of Python 2.6 scheduled for
early october 2008.

Of course I'd assist if questions or problems would arise.

Regards
Gregor
Here is a version that does fill:
from turtle import *
import time

setup(width=1000, height=700, startx=0, starty=0)
for n in range(2):
   color_name = 'red'
   x, y = 50, 50
   color(color_name)
   print color_name
   up()
   goto(x, y)
   down()
   begin_fill()
   goto(x, -y)
   goto(-x, -y)
   goto(-x, y)
   end_fill()
   print "end_fill()"
   goto(x, y)
   time.sleep(1)
   clear()

I have no idea why this one works and yours doesn't. Your program is
very similar to the filled square in turtle.demo() which does work.

The filling is implemented by drawing a polygon on a Tkinter Canvas;
is there something strange about polygons?

Kent
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to