odd drawing problem with turtle.py

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

odd drawing problem with turtle.py

Brian Blais
I'm on Python 2.5, but using the updated turtle.py Version 1.0.1 - 24. 9. 2009.  The following script draws 5 circles, which it is supposed to, but then doesn't draw the second turtle which is supposed to simply move forward.  Any ideas?

from turtle import *
from numpy.random import randint

resetscreen()

class Circle(object):

    def __init__(self,x,y,r,color):
        self.x=x
        self.y=y
        self.r=r
        self.color=color
        
        self.turtle=Turtle(visible=False)
        self.turtle.tracer(False)
        self.draw()
        
    def draw(self):
        self.turtle.penup()
        self.turtle.setposition(self.x,self.y)
        self.turtle.setheading(0)
        self.turtle.backward(self.r)
        self.turtle.pendown()
        self.turtle.fill(True)
        self.turtle.pencolor("black")
        self.turtle.fillcolor(self.color)
        self.turtle.circle(self.r)        
        self.turtle.fill(False)
        self.turtle.penup()


for i in range(5):

    c=Circle(randint(-350,350),randint(-250,250),10,"red")
    
    
T=Turtle()
T.forward(100)
T.forward(100)








thanks,


bb



_______________________________________________
Edu-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/edu-sig
Reply | Threaded
Open this post in threaded view
|

Re: odd drawing problem with turtle.py

kirby urner-4
I don't see where you've defined a Turtle class to instantiate sir.

Perhaps rename Circle to Turtle and rewrite the circle-drawing expression as:

>     c=Turtle(randint(-350,350),randint(-250,250),10,"red")

You are making progress with a wrapper class for the Standard Library turtle.

That's a well-known design pattern and a good way to get extra features
sometimes.

Kirby

On Sun, Jan 31, 2010 at 4:27 PM, Brian Blais <[hidden email]> wrote:

> I'm on Python 2.5, but using the updated turtle.py Version 1.0.1 - 24. 9.
> 2009.  The following script draws 5 circles, which it is supposed to, but
> then doesn't draw the second turtle which is supposed to simply move
> forward.  Any ideas?
> from turtle import *
> from numpy.random import randint
> resetscreen()
> class Circle(object):
>     def __init__(self,x,y,r,color):
>         self.x=x
>         self.y=y
>         self.r=r
>         self.color=color
>
>         self.turtle=Turtle(visible=False)
>         self.turtle.tracer(False)
>         self.draw()
>
>     def draw(self):
>         self.turtle.penup()
>         self.turtle.setposition(self.x,self.y)
>         self.turtle.setheading(0)
>         self.turtle.backward(self.r)
>         self.turtle.pendown()
>         self.turtle.fill(True)
>         self.turtle.pencolor("black")
>         self.turtle.fillcolor(self.color)
>         self.turtle.circle(self.r)
>         self.turtle.fill(False)
>         self.turtle.penup()
>
> for i in range(5):
>     c=Circle(randint(-350,350),randint(-250,250),10,"red")
>
>
> T=Turtle()
> T.forward(100)
> T.forward(100)
>
>
>
>
>
>
>
> thanks,
>
> bb
> --
> Brian Blais
> [hidden email]
> http://web.bryant.edu/~bblais
> http://bblais.blogspot.com/
>
>
>
> _______________________________________________
> Edu-sig mailing list
> [hidden email]
> http://mail.python.org/mailman/listinfo/edu-sig
>
>
_______________________________________________
Edu-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/edu-sig
Reply | Threaded
Open this post in threaded view
|

Re: odd drawing problem with turtle.py

Vern Ceder
kirby urner wrote:
> I don't see where you've defined a Turtle class to instantiate sir.

The Turtle class is part of the turtle library, so that's not an issue.

> On Sun, Jan 31, 2010 at 4:27 PM, Brian Blais <[hidden email]> wrote:
>> I'm on Python 2.5, but using the updated turtle.py Version 1.0.1 - 24. 9.
>> 2009.  The following script draws 5 circles, which it is supposed to, but
>> then doesn't draw the second turtle which is supposed to simply move
>> forward.  Any ideas?

You mean you just want a turtle, but no line? If so, does instantiating
T with T = Turtle(visible=True) help?

Cheers,
Vern

>> from turtle import *
>> from numpy.random import randint
>> resetscreen()
>> class Circle(object):
>>     def __init__(self,x,y,r,color):
>>         self.x=x
>>         self.y=y
>>         self.r=r
>>         self.color=color
>>
>>         self.turtle=Turtle(visible=False)
>>         self.turtle.tracer(False)
>>         self.draw()
>>
>>     def draw(self):
>>         self.turtle.penup()
>>         self.turtle.setposition(self.x,self.y)
>>         self.turtle.setheading(0)
>>         self.turtle.backward(self.r)
>>         self.turtle.pendown()
>>         self.turtle.fill(True)
>>         self.turtle.pencolor("black")
>>         self.turtle.fillcolor(self.color)
>>         self.turtle.circle(self.r)
>>         self.turtle.fill(False)
>>         self.turtle.penup()
>>
>> for i in range(5):
>>     c=Circle(randint(-350,350),randint(-250,250),10,"red")
>>
>>
>> T=Turtle()
>> T.forward(100)
>> T.forward(100)
>>
>>
>>
>>
>>
>>
>>
>> thanks,
>>
>> bb
>> --
>> Brian Blais
>> [hidden email]
>> http://web.bryant.edu/~bblais
>> http://bblais.blogspot.com/
>>
>>
>>
>> _______________________________________________
>> Edu-sig mailing list
>> [hidden email]
>> http://mail.python.org/mailman/listinfo/edu-sig
>>
>>
> _______________________________________________
> Edu-sig mailing list
> [hidden email]
> http://mail.python.org/mailman/listinfo/edu-sig

--
This time for sure!
    -Bullwinkle J. Moose
-----------------------------
Vern Ceder, Director of Technology
Canterbury School, 3210 Smith Road, Ft Wayne, IN 46804
[hidden email]; 260-436-0746; FAX: 260-436-5137

The Quick Python Book, 2nd Ed - http://bit.ly/bRsWDW
_______________________________________________
Edu-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/edu-sig
Reply | Threaded
Open this post in threaded view
|

Re: odd drawing problem with turtle.py

kirby urner-4
On Sun, Jan 31, 2010 at 8:07 PM, Vern Ceder <[hidden email]> wrote:
> kirby urner wrote:
>>
>> I don't see where you've defined a Turtle class to instantiate sir.
>
> The Turtle class is part of the turtle library, so that's not an issue.
>

Hey, good point Vern, not firing on all cylinders over here.

So I just commented out the Circle loop, went straight to the Turtle
part at the end.

It works OK for me, even without the visible=True.

I'm on Python 2.6 on Win7 and I took out the numpy randint in favor of
random randint.

turtle.py in lib_tk:  # Version 1.0.1 - 24. 9. 2009

I'm maybe not the right beta tester though, as after I uncomment the
circle loop, I just get an hour-glass on my Tk canvas and no drawing,
no error message either, even with visible=True in the init.

Not sure what that's about yet...

Hey, I just found out about piratepad.net, another shared white board solution.
Was helping a dude in Indonesia debug a VPython script just a moment ago,
with variable names in Indonesian (Latin-1 spellings at least).

I've appended what we're working on.

[ on second thought, I'll spare ya ]

Kirby
>>>        self.turtle=Turtle(visible=False)

Does visibility *and* pen need to be controlled?  Sorry for
the basic question, but seems if pen is up...
_______________________________________________
Edu-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/edu-sig
Reply | Threaded
Open this post in threaded view
|

Re: odd drawing problem with turtle.py

Brian Blais
In reply to this post by kirby urner-4
On Jan 31, 2010, at 23:05 , John Posner wrote:

Try commenting out this statement:

   self.turtle.tracer(False)

That helps on Python 2.6.4.


interesting.  It seems as if the tracer property is a global one:

In [1]:t1=Turtle()

In [2]:t1.tracer()
Out[2]:1

In [3]:t1.tracer(False)

In [4]:t1.tracer()
Out[4]:0

In [5]:t2=Turtle()

In [6]:t2.tracer()
Out[6]:0

In [7]:t2.tracer(True)

In [8]:t1.tracer()
Out[8]:1

looks like I need to set the tracer manually. 

however, even if the tracer is off, shouldn't it still draw the line?  when I put in the T.tracer(True) it works, but I shouldn't need to I think.


On Jan 31, 2010, at 21:11 , kirby urner wrote:

I don't see where you've defined a Turtle class to instantiate sir.

Turtle is given in turtle.py.  I should have subclassed it, but I was being lazy.  :)

thanks for the fast replies!


bb


On Sun, Jan 31, 2010 at 4:27 PM, Brian Blais <[hidden email]> wrote:
I'm on Python 2.5, but using the updated turtle.py Version 1.0.1 - 24. 9.
2009.  The following script draws 5 circles, which it is supposed to, but
then doesn't draw the second turtle which is supposed to simply move
forward.  Any ideas?
from turtle import *
from numpy.random import randint
resetscreen()
class Circle(object):
    def __init__(self,x,y,r,color):
        self.x=x
        self.y=y
        self.r=r
        self.color=color

        self.turtle=Turtle(visible=False)
        self.turtle.tracer(False)
        self.draw()

    def draw(self):
        self.turtle.penup()
        self.turtle.setposition(self.x,self.y)
        self.turtle.setheading(0)
        self.turtle.backward(self.r)
        self.turtle.pendown()
        self.turtle.fill(True)
        self.turtle.pencolor("black")
        self.turtle.fillcolor(self.color)
        self.turtle.circle(self.r)
        self.turtle.fill(False)
        self.turtle.penup()

for i in range(5):
    c=Circle(randint(-350,350),randint(-250,250),10,"red")


T=Turtle()
T.forward(100)
T.forward(100)







thanks,

bb
--
Brian Blais



_______________________________________________
Edu-sig mailing list





_______________________________________________
Edu-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/edu-sig
Reply | Threaded
Open this post in threaded view
|

Re: odd drawing problem with turtle.py

Vern Ceder
Brian Blais wrote:

>> On Jan 31, 2010, at 23:05 , John Posner wrote:
>>
>>> Try commenting out this statement:
>>>
>>>    self.turtle.tracer(False)
>>>
>>> That helps on Python 2.6.4.
>
>
> interesting.  It seems as if the tracer property is a global one:

Actually, the tracer method that does the work is part of the
TurtleScreen class, and individual Turtle instances just access the
tracer method of the TurtleScreen they inhabit... if that makes sense.
So since your turtles are on the same screen, yes, in effect, tracer is
sort of global.

Cheers,
Vern

>
> In [1]:t1=Turtle()
>
> In [2]:t1.tracer()
> Out[2]:1
>
> In [3]:t1.tracer(False)
>
> In [4]:t1.tracer()
> Out[4]:0
>
> In [5]:t2=Turtle()
>
> In [6]:t2.tracer()
> Out[6]:0
>
> In [7]:t2.tracer(True)
>
> In [8]:t1.tracer()
> Out[8]:1
>
> looks like I need to set the tracer manually.
>
> however, even if the tracer is off, shouldn't it still draw the line?
>  when I put in the T.tracer(True) it works, but I shouldn't need to I think.
>
>
> On Jan 31, 2010, at 21:11 , kirby urner wrote:
>
>> I don't see where you've defined a Turtle class to instantiate sir.
>
> Turtle is given in turtle.py.  I should have subclassed it, but I was
> being lazy.  :)
>
> thanks for the fast replies!
>
>
> bb
>
>
>> On Sun, Jan 31, 2010 at 4:27 PM, Brian Blais <[hidden email]
>> <mailto:[hidden email]>> wrote:
>>> I'm on Python 2.5, but using the updated turtle.py Version 1.0.1 - 24. 9.
>>> 2009.  The following script draws 5 circles, which it is supposed to, but
>>> then doesn't draw the second turtle which is supposed to simply move
>>> forward.  Any ideas?
>>> from turtle import *
>>> from numpy.random import randint
>>> resetscreen()
>>> class Circle(object):
>>>     def __init__(self,x,y,r,color):
>>>         self.x=x
>>>         self.y=y
>>>         self.r=r
>>>         self.color=color
>>>
>>>         self.turtle=Turtle(visible=False)
>>>         self.turtle.tracer(False)
>>>         self.draw()
>>>
>>>     def draw(self):
>>>         self.turtle.penup()
>>>         self.turtle.setposition(self.x,self.y)
>>>         self.turtle.setheading(0)
>>>         self.turtle.backward(self.r)
>>>         self.turtle.pendown()
>>>         self.turtle.fill(True)
>>>         self.turtle.pencolor("black")
>>>         self.turtle.fillcolor(self.color)
>>>         self.turtle.circle(self.r)
>>>         self.turtle.fill(False)
>>>         self.turtle.penup()
>>>
>>> for i in range(5):
>>>     c=Circle(randint(-350,350),randint(-250,250),10,"red")
>>>
>>>
>>> T=Turtle()
>>> T.forward(100)
>>> T.forward(100)
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> thanks,
>>>
>>> bb
>>> --
>>> Brian Blais
>>> [hidden email] <mailto:[hidden email]>
>>> http://web.bryant.edu/~bblais
>>> http://bblais.blogspot.com/
>>>
>>>
>>>
>>> _______________________________________________
>>> Edu-sig mailing list
>>> [hidden email] <mailto:[hidden email]>
>>> http://mail.python.org/mailman/listinfo/edu-sig
>>>
>>>
>
> --
> Brian Blais
> [hidden email] <mailto:[hidden email]>
> http://web.bryant.edu/~bblais
> http://bblais.blogspot.com/
>
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Edu-sig mailing list
> [hidden email]
> http://mail.python.org/mailman/listinfo/edu-sig

--
This time for sure!
    -Bullwinkle J. Moose
-----------------------------
Vern Ceder, Director of Technology
Canterbury School, 3210 Smith Road, Ft Wayne, IN 46804
[hidden email]; 260-436-0746; FAX: 260-436-5137

The Quick Python Book, 2nd Ed - http://bit.ly/bRsWDW
_______________________________________________
Edu-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/edu-sig
Reply | Threaded
Open this post in threaded view
|

Re: odd drawing problem with turtle.py

kirby urner-4
In reply to this post by Brian Blais

On Mon, Feb 1, 2010 at 3:27 AM, Brian Blais <[hidden email]> wro

I don't see where you've defined a Turtle class to instantiate sir.

Turtle is given in turtle.py.  I should have subclassed it, but I was being lazy.  :)

thanks for the fast replies!

 

bb





No obvious need to subclass. 

You weren't being lazy, I was being sloppy.

I'm glad Vern caught my error right away.

Kirby


_______________________________________________
Edu-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/edu-sig