Re: [Tutor] Ongoing trouble with Turtle's end_fill() - caused by a bug in turtle.py

2008-08-07 Thread Dick Moores
On Wed, Aug 6, 2008 at 5:09 PM, Gregor Lingl [EMAIL PROTECTED] wrote:
 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,


Yes, it does! I've pasted a version at
http://py77.python.pastebin.com/f228f64f. Thank you!


 (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.


I got Python2.6 beta2 and copied its turtle.py to my Python 2.5 after
renaming it turtle26.py. By now I've spent several hours trying to
figure out how to get my program to work well with it. I don't know if
I've discovered any bugs, but here are some of the problems I have:

1. The turtle has some behavior I don't see how to eliminate. If you
refer to lines 223, 225, 227, 229, etc., you'll see that the turtle
always faces in the direction it is moving when drawing a rectangle.
Using the Python2.6 beta2 version of turtle.py, the turtle can be seen
at each corner spinning to orient itself to the new direction. I don't
want this. I thought I could remove the spinning effect by setting the
turtle's shape to a circle. But the circle is way bigger than the
default turtle. No spinning, but not what I'm after.

2. The turtle can also be seen moving from the last corner of the last
rectangle to the first corner of the next. I don't want this.

3. When the screen is cleared between cycles by line 367, the blank
screen shows for a second or so. I don't want this.
In my program using the old turtle I've had to create
colored-backgrounds by drawing a rectangle almost as large as the
screen (see my draw_background() beginning at line 365). With the new
turtle, the background color can be set by, for example,
screen.bgcolor(orange). But even so, in the V16 I was trying to
write, that blank screen still shows for a second or so. With the old
turtle, the transition from one background to another seems
instantaneous. No white blank screen visible at all.

4. I've attempted to make the turtle invisible, but haven't succeeded.

I'm guessing that all the problems I've mentioned aren't the result of
bugs--rather, I just don't understand the doc.


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


Thanks.

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


Re: [Tutor] Ongoing trouble with Turtle's end_fill() - caused by a bug in turtle.py

2008-08-07 Thread Dick Moores
On Thu, Aug 7, 2008 at 9:54 AM, Dick Moores [EMAIL PROTECTED] wrote:
 4. I've attempted to make the turtle invisible, but haven't succeeded.

Got it!  hideturtle()
http://docs.python.org/dev/library/turtle.html#turtle.hideturtle

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


Re: [Tutor] Ongoing trouble with Turtle's end_fill() - caused by a bug in turtle.py

2008-08-06 Thread Gregor Lingl



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