Re: Turtle module

2021-05-26 Thread Greg Ewing

On 27/05/21 4:17 am, Chris Angelico wrote:

Worst case, it
is technically available as the ._fullcircle member, but I would
advise against using that if you can help it!


If you're worried about that, you could create your own
turle subclass that tracks the state how you want.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: Turtle module

2021-05-26 Thread boB Stepp
On Wed, May 26, 2021 at 10:59 AM Michael F. Stemper  wrote:

> In order to turn the turtle, I need to select a way to represent
> angles. I could use either degrees or radians (or, I suppose,
> grads). However, for my functions to work, I need to set the
> turtle to that mode. This means that I could possibly mess up
> things for the caller. What I would like to do is capture the
> angle-representation mode on entry and restore it on return.
> However, looking through the methods of turtle.Turtle(), I
> can't find any means of capturing this information

In the "Tell Turtle's state" section
(https://docs.python.org/3/library/turtle.html#tell-turtle-s-state) I
would think that you could roll your own function by using your
knowledge of the coordinates of where the turtle is at and the
turtle.towards(0, 0).  By computing your own angle (knowing what units
you are using) and comparing with what is returned you should be able
to determine what angular units are currently set.

HTH!
boB Stepp
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Turtle module

2021-05-26 Thread Chris Angelico
On Thu, May 27, 2021 at 6:51 AM Michael F. Stemper  wrote:
>
> On 26/05/2021 11.17, Chris Angelico wrote:
> > On Thu, May 27, 2021 at 1:59 AM Michael F. Stemper  
> > wrote:
>
>
> >>What I would like to do is capture the
> >> angle-representation mode on entry and restore it on return.
> >> However, looking through the methods of turtle.Turtle(), I
> >> can't find any means of capturing this information.
> >>
> >> Similarly, I'd like to return with the pen in the same state
> >> (up or down) as when my functions were called. Again, I can't
> >> find any way to query the pen state.
> >>
> >> How can my function get this information? Or do I need to be
> >> sloppy and let the callers beware?
> >
> > For the most part, this is what you want:
> >
> > https://docs.python.org/3/library/turtle.html#turtle.pen
>
> Just found the same thing myself and came back to report it. But,
> immediately after your link is:
> <https://docs.python.org/3/library/turtle.html#turtle.isdown>
> which seems even better for up/down.

Yeah, if that's the only thing you need.

> > It doesn't seem to include the fullcircle state (which is what
> > .degrees() and .radians() set), and I'm not sure why. Worst case, it
> > is technically available as the ._fullcircle member, but I would
> > advise against using that if you can help it!
>
> Well, I'll take your advice and not use it. Seems really sloppy to
> change an attribute of an object as a side-effect, but I guess that
> I'll have to be sloppy.
>

If this matters to you, here's what I'd recommend: Propose that the
fullcircle state be added to what pen() returns and can update, and
also possibly propose a context manager, so you can do something like
this:

def f():
with turt.local():
turt.pendown()
...

# once we get here, the turtle's pen state will have been restored

I'm not the person to ask about these, as I don't use the turtle
module, but those would seem fairly plausible enhancements.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Turtle module

2021-05-26 Thread Michael F. Stemper

On 26/05/2021 13.24, Stefan Ram wrote:

"Michael F. Stemper"  writes:

   What I would like to do is capture the
angle-representation mode on entry and restore it on return.



   another one:

def f( turtle_ ):
 my_turtle = turtle_.clone()
 # now work with my_turtle only


Oooh, I like this. It's proof against other types of bullets that
might come along.


   All of the above ideas have *not* been tested.


My first test found me with two arrows (turtle icons?) upon return.
I immediately realized what caused it, and put
   t.hideturtle()
at the end of my testbed function.

Thanks,
--
Michael F. Stemper
Economists have correctly predicted seven of the last three recessions.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Turtle module

2021-05-26 Thread Michael F. Stemper

On 26/05/2021 11.17, Chris Angelico wrote:

On Thu, May 27, 2021 at 1:59 AM Michael F. Stemper  wrote:




   What I would like to do is capture the
angle-representation mode on entry and restore it on return.
However, looking through the methods of turtle.Turtle(), I
can't find any means of capturing this information.

Similarly, I'd like to return with the pen in the same state
(up or down) as when my functions were called. Again, I can't
find any way to query the pen state.

How can my function get this information? Or do I need to be
sloppy and let the callers beware?


For the most part, this is what you want:

https://docs.python.org/3/library/turtle.html#turtle.pen


Just found the same thing myself and came back to report it. But,
immediately after your link is:

which seems even better for up/down.


It doesn't seem to include the fullcircle state (which is what
.degrees() and .radians() set), and I'm not sure why. Worst case, it
is technically available as the ._fullcircle member, but I would
advise against using that if you can help it!


Well, I'll take your advice and not use it. Seems really sloppy to
change an attribute of an object as a side-effect, but I guess that
I'll have to be sloppy.

Thanks
--
Michael F. Stemper
Deuteronomy 10:18-19
--
https://mail.python.org/mailman/listinfo/python-list


Re: Turtle module

2021-05-26 Thread Chris Angelico
On Thu, May 27, 2021 at 1:59 AM Michael F. Stemper  wrote:
> In order to turn the turtle, I need to select a way to represent
> angles. I could use either degrees or radians (or, I suppose,
> grads). However, for my functions to work, I need to set the
> turtle to that mode. This means that I could possibly mess up
> things for the caller. What I would like to do is capture the
> angle-representation mode on entry and restore it on return.
> However, looking through the methods of turtle.Turtle(), I
> can't find any means of capturing this information.
>
> Similarly, I'd like to return with the pen in the same state
> (up or down) as when my functions were called. Again, I can't
> find any way to query the pen state.
>
> How can my function get this information? Or do I need to be
> sloppy and let the callers beware?

For the most part, this is what you want:

https://docs.python.org/3/library/turtle.html#turtle.pen

It doesn't seem to include the fullcircle state (which is what
.degrees() and .radians() set), and I'm not sure why. Worst case, it
is technically available as the ._fullcircle member, but I would
advise against using that if you can help it!

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Turtle module

2021-05-26 Thread Michael F. Stemper

I recently discovered the turtle module and have been playing
around with it for the last few days. I've started writing some
functions for turtles, and would like to make them a bit more
robustly than what I currently have.

In particular, I'd like the state of the turtle to be more or
less the same after the function return as it was before the
function invocation.

In order to turn the turtle, I need to select a way to represent
angles. I could use either degrees or radians (or, I suppose,
grads). However, for my functions to work, I need to set the
turtle to that mode. This means that I could possibly mess up
things for the caller. What I would like to do is capture the
angle-representation mode on entry and restore it on return.
However, looking through the methods of turtle.Turtle(), I
can't find any means of capturing this information.

Similarly, I'd like to return with the pen in the same state
(up or down) as when my functions were called. Again, I can't
find any way to query the pen state.

How can my function get this information? Or do I need to be
sloppy and let the callers beware?

--
Michael F. Stemper
2 Chronicles 19:7
--
https://mail.python.org/mailman/listinfo/python-list


Re: tilted text in the turtle module

2010-11-25 Thread Yingjie Lan
--- On Fri, 11/26/10, Steve Holden  wrote:

> From: Steve Holden 
> Subject: Re: tilted text in the turtle module
> To: python-list@python.org
> Date: Friday, November 26, 2010, 4:16 AM
> On 11/25/2010 5:58 PM, Yingjie Lan
> wrote:
> > --- On Thu, 11/25/10, Steve Holden 
> wrote:
> >>> And even if I made a patch, 
> >>> then how to publish it?
> >>>
> >> Once you have a patch, attach it to the issue as a
> file and
> >> try and get
> >> it reviewed by a developer for incorporation into
> a future
> >> release.
> >>
> >> Note that no Python 2.8 release is planned, so you
> would
> >> best
> >> concentrate your effort on the 3.x series.
> >>
> > 
> > I see. I suppose one could post a message somewhere
> > to get the attention? 
> > 
> > Thanks for the pointer.
> > 
> One would normally make a post on the python-dev list to
> get the
> attention of developers. If you want to *guarantee* that
> your issue gets
> attention then you can review five existing issues and
> advance them a
> little to help the development team.
> 

Sound advices. Many thanks!

Yingjie


  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tilted text in the turtle module

2010-11-25 Thread Steve Holden
On 11/25/2010 5:58 PM, Yingjie Lan wrote:
> --- On Thu, 11/25/10, Steve Holden  wrote:
>>> And even if I made a patch, 
>>> then how to publish it?
>>>
>> Once you have a patch, attach it to the issue as a file and
>> try and get
>> it reviewed by a developer for incorporation into a future
>> release.
>>
>> Note that no Python 2.8 release is planned, so you would
>> best
>> concentrate your effort on the 3.x series.
>>
> 
> I see. I suppose one could post a message somewhere
> to get the attention? 
> 
> Thanks for the pointer.
> 
One would normally make a post on the python-dev list to get the
attention of developers. If you want to *guarantee* that your issue gets
attention then you can review five existing issues and advance them a
little to help the development team.

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon 2011 Atlanta March 9-17   http://us.pycon.org/
See Python Video!   http://python.mirocommunity.org/
Holden Web LLC http://www.holdenweb.com/

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tilted text in the turtle module

2010-11-25 Thread Yingjie Lan
--- On Thu, 11/25/10, Steve Holden  wrote:
> > And even if I made a patch, 
> > then how to publish it?
> > 
> Once you have a patch, attach it to the issue as a file and
> try and get
> it reviewed by a developer for incorporation into a future
> release.
> 
> Note that no Python 2.8 release is planned, so you would
> best
> concentrate your effort on the 3.x series.
> 

I see. I suppose one could post a message somewhere
to get the attention? 

Thanks for the pointer.

Regards,

Yingjie


  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tilted text in the turtle module

2010-11-25 Thread Steve Holden
On 11/25/2010 10:49 AM, Yingjie Lan wrote:
> --- On Thu, 11/25/10, Steve Holden  wrote:
>> From: Steve Holden 
>> Subject: Re: tilted text in the turtle module
>> To: python-list@python.org
>> Date: Thursday, November 25, 2010, 7:00 PM
>> On 11/25/2010 5:06 AM, Yingjie Lan
>> wrote:
>> This sounds like a good idea. To request a feature you
>> should create an
>> account (if you do not already have one) on bugs.python.org
>> and create a
>> new issue (assuming a search reveals that there is not
>> already such an
>> issue).
>>
> 
> Thanks I just did that.
>  
>> You may find if you look at the module's code that you can
>> imagine how
>> to  make the change. If not, the request will wait
>> until some maintainer
>> sees it and has time.
>>
> 
> I don't know much about tkinter, 
> not sure if I can contribute.
> And even if I made a patch, 
> then how to publish it?
> 
Once you have a patch, attach it to the issue as a file and try and get
it reviewed by a developer for incorporation into a future release.

Note that no Python 2.8 release is planned, so you would best
concentrate your effort on the 3.x series.

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon 2011 Atlanta March 9-17   http://us.pycon.org/
See Python Video!   http://python.mirocommunity.org/
Holden Web LLC http://www.holdenweb.com/

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tilted text in the turtle module

2010-11-25 Thread Yingjie Lan
--- On Thu, 11/25/10, Steve Holden  wrote:
> From: Steve Holden 
> Subject: Re: tilted text in the turtle module
> To: python-list@python.org
> Date: Thursday, November 25, 2010, 7:00 PM
> On 11/25/2010 5:06 AM, Yingjie Lan
> wrote:
> This sounds like a good idea. To request a feature you
> should create an
> account (if you do not already have one) on bugs.python.org
> and create a
> new issue (assuming a search reveals that there is not
> already such an
> issue).
>

Thanks I just did that.
 
> You may find if you look at the module's code that you can
> imagine how
> to  make the change. If not, the request will wait
> until some maintainer
> sees it and has time.
> 

I don't know much about tkinter, 
not sure if I can contribute.
And even if I made a patch, 
then how to publish it?

Regards,

Yingjie


  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tilted text in the turtle module

2010-11-25 Thread Steve Holden
On 11/25/2010 5:06 AM, Yingjie Lan wrote:
> First of all, I'd like to express my deep gratidute to the author of this 
> module, it is such a fun module to work with and to teach python as a first 
> programming language.
> 
> Secondly, I would like to request a feature if it is not too hard to achieve. 
> Currently, you can only write texts horizontally, no matter what is the 
> current orientation of the turtle pen. I wonder if it is possible to write 
> text in any direction when we control the heading of the turtle? For example, 
> the following code would write a vertically oriented text:
> 
> setheading(90) #turtle facing up
> write("vertical text!") 
> 
> Thanks a lot!
> 
Yingjie:

This sounds like a good idea. To request a feature you should create an
account (if you do not already have one) on bugs.python.org and create a
new issue (assuming a search reveals that there is not already such an
issue).

You may find if you look at the module's code that you can imagine how
to  make the change. If not, the request will wait until some maintainer
sees it and has time.

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon 2011 Atlanta March 9-17   http://us.pycon.org/
See Python Video!   http://python.mirocommunity.org/
Holden Web LLC http://www.holdenweb.com/

-- 
http://mail.python.org/mailman/listinfo/python-list


tilted text in the turtle module

2010-11-25 Thread Yingjie Lan
First of all, I'd like to express my deep gratidute to the author of this 
module, it is such a fun module to work with and to teach python as a first 
programming language.

Secondly, I would like to request a feature if it is not too hard to achieve. 
Currently, you can only write texts horizontally, no matter what is the current 
orientation of the turtle pen. I wonder if it is possible to write text in any 
direction when we control the heading of the turtle? For example, the following 
code would write a vertically oriented text:

setheading(90) #turtle facing up
write("vertical text!") 

Thanks a lot!

Yingjie


  
-- 
http://mail.python.org/mailman/listinfo/python-list


mouse input in turtle module

2010-02-03 Thread Brian Blais

Hello,

I would like to find a way to pause, and get mouse input in the  
turtle module.  Since it is built on tk, I thought perhaps there  
would be an easy way, but I am stumped.  Specifically, I'd like  
something like:


x,y,button=mouse_input() # pause in here until the mouse is clicked  
in the turtle window


I know about the screenclick, where I can define a callback but I  
couldn't rig it to pause until a mouse clicked, even using global  
flags.  Is there an example of this somewhere?  For a bonus, I'd love  
to be able to  out of it, either raising an exception or return  
a button=-1 or something.



thanks,

Brian Blais

--
Brian Blais
bbl...@bryant.edu
http://web.bryant.edu/~bblais
http://bblais.blogspot.com/



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Edu-sig] teaching python using turtle module

2009-12-01 Thread kirby urner
Gregor FYI:

You'll find me linking to one Gregor in Vienna in this blog post, just
beneath an archival photo of work by Alexander Graham Bell.[1]

http://worldgame.blogspot.com/2009/12/meeting-with-sam.html

... providing more context and spin for this rhombic triancontahedron
thread, all that much strong thanks to you.

Kirby

[1] Eber, Dorothy Harley. Genius At Work. about AGB is one of my fave
syllabus entries, obscure and fun.

On Mon, Nov 30, 2009 at 4:52 PM, kirby urner  wrote:
> On Mon, Nov 30, 2009 at 4:31 PM, Gregor Lingl  wrote:
>
> << fascinating code >>
>
>>
>> Hoping, you will find this a bit interesting,
>> best regards
>>
>> Gregor
>>
>
> Really enlightening, both mathematically and from a coding point of
> view.  I hadn't used turtle.py enough yet to know about the built-in
> "context turtle" if you want to just say "forward" and forgo
> specifying a target.  That's a nice Logo-ish touch.
>
> Your take on the T is most excellent.
>
> With your permission, I'd be happy to add both versions with
> attribution to my online version of tmod.py for the benefit of future
> students, and/or I could simply link to this post in the edu-sig
> archives (why not both?).
>
> Kirby
>
>
> --
 from mars import math
> http://www.wikieducator.org/Digital_Math
>



-- 
>>> from mars import math
http://www.wikieducator.org/Digital_Math
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Edu-sig] teaching python using turtle module

2009-11-30 Thread kirby urner
On Mon, Nov 30, 2009 at 4:31 PM, Gregor Lingl  wrote:

<< fascinating code >>

>
> Hoping, you will find this a bit interesting,
> best regards
>
> Gregor
>

Really enlightening, both mathematically and from a coding point of
view.  I hadn't used turtle.py enough yet to know about the built-in
"context turtle" if you want to just say "forward" and forgo
specifying a target.  That's a nice Logo-ish touch.

Your take on the T is most excellent.

With your permission, I'd be happy to add both versions with
attribution to my online version of tmod.py for the benefit of future
students, and/or I could simply link to this post in the edu-sig
archives (why not both?).

Kirby


-- 
>>> from mars import math
http://www.wikieducator.org/Digital_Math
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Edu-sig] teaching python using turtle module

2009-11-30 Thread Gregor Lingl



kirby urner schrieb:

I'm glad turtle graphics intersected my thinking re extended precision
decimals (Decimal type) on edu-sig just now.

I've updated my tmods.py to contain a turtle rendering the plane-net of a T-mod:

http://www.4dsolutions.net/ocn/python/tmod.py (runnable source)
http://www.flickr.com/photos/17157...@n00/4147429781/  (GUI view)
  

Nice tiny app! Albeit not an example for using the if statement ;-)
Just to show you how turtle.py enables you to implement this
using quite different approaches to doing geometry, I'd like to add
two more implementations.

Besides you may notice that these do not rely on rather complicated
calculations of distances and angles, using the Pythagorean theorem
and trigonometrics but only on a few more fundamental properties of
the figure.

# Version 2 - using coordinate geometry without coordinates ;-)
# a different implementation for Kirby's "Plane Net for T-module"

from turtle import *
from math import sqrt

PHI = (sqrt(5)-1)/2

def planeNet(h=500): 
  setup(560,560)

  title("Plane Net for T-module")
  penup()
  back(h/2); left(90); back(h/2); right(90)
  pendown()

  forward(h); left(90)
  forward(h*PHI); A = pos(); forward(h-h*PHI); left(90)
  forward(h*PHI); B = pos(); forward(h-h*PHI); left(90)
  forward(h); C = pos()

  for P in A, B, C:
 goto(P)


# Version 3 - stamping simple transforms of the shape of
#  an isosceles rectangular triangle:

from turtle import Screen, Turtle
from math import sqrt

GOLDEN_RATIO = (sqrt(5)-1)/2

def planeNet(h=500.0, phi=GOLDEN_RATIO): 
  s = Screen(); s.setup(560,560); s.title("Plane Net for T-module")

  s.register_shape("recttriangle", ((0, 0), (h, 0), (0, h)))
  designer = Turtle(shape="recttriangle")
  designer.color("black","")
  designer.penup()
  designer.goto(-h/2, h/2)

  for width, height in ((1, 1-phi), (phi, 1-phi), (phi, 1)):
 designer.shapesize(width, height)
 designer.stamp()
 designer.forward(h)
 designer.right(90)
  designer.hideturtle()

Hoping, you will find this a bit interesting,
best regards

Gregor




Here's the graphical output:

http://www.flickr.com/photos/17157...@n00/4148139184/in/photostream/
(Python 3.1)

If you actually wanna fold the T, you need to snip off the cap and
reverse it, per this diagram:

http://www.rwgrayprojects.com/synergetics/s09/figs/f86515.html

120 of them, 60 folded left, 60 folded right, all of volume 1/24, make
the volume 5 rhombic triacontahedron.

http://www.rwgrayprojects.com/synergetics/s09/figs/f86419.html

If you blow up the volume by 3/2, to 7.5, the radius becomes phi /
sqrt(2) -- what we're showing with Decimals.

The reason this seems unfamiliar is the unit of volume is the
tetrahedron formed by any four equi-radiused balls in inter-tangency.

I'm spinning this as Martian Math these days, yakking on
math-thinking-l about it, learned it from Bucky Fuller, Dave Koski et
al.

Kirby

  

--
http://mail.python.org/mailman/listinfo/python-list


Re: [Edu-sig] teaching python using turtle module

2009-11-30 Thread Alf P. Steinbach

* Edward Cherlin:

On Sun, Nov 29, 2009 at 11:34, Brian Blais  wrote:


After a bit of playing, I realized that I couldn't think of many exaples
which use turtle with conditional structures (if- and while- statements),


Repeat is used much more often. but of course we can provide examples
of any behavior you like. I like to use the turtle to generate
sequences, where I can use a conditional to stop when the turtle would
go off the screen. Fibonacci numbers, for example, or exponentials.
Similarly for spirals of various types. Simple cases like those are
easy to do in TA, while more complex sequences could use Python. There
are several fractal examples using loops provided with Sugar on a
Stick, including variations on Siepinksi constructions, and the Koch
Snowflake.


In ch 2 of

  http://preview.tinyurl.com/ProgrammingBookP3>

I use a turtle-generated spiral as the first example of a while loop.

I haven't got that far yet with that chapter, but I halfway plan on including a 
turtle graphics solve-a-maze example, which would/will be an example of 
conditionals with the turtle as a kind of actor making decisions.




or
functions that return values, as opposed to "procedures" like:
def square(length):
forward(length)
right(90)
forward(length)
right(90)
forward(length)
right(90)
forward(length)
right(90)


Plotting a graph. Some examples of that in ch 2 of aforementioned URL.


Cheers & hth.,

- Alf
--
http://mail.python.org/mailman/listinfo/python-list


Re: [Edu-sig] teaching python using turtle module

2009-11-30 Thread kirby urner
I'm glad turtle graphics intersected my thinking re extended precision
decimals (Decimal type) on edu-sig just now.

I've updated my tmods.py to contain a turtle rendering the plane-net of a T-mod:

http://www.4dsolutions.net/ocn/python/tmod.py (runnable source)
http://www.flickr.com/photos/17157...@n00/4147429781/  (GUI view)

Here's the graphical output:

http://www.flickr.com/photos/17157...@n00/4148139184/in/photostream/
(Python 3.1)

If you actually wanna fold the T, you need to snip off the cap and
reverse it, per this diagram:

http://www.rwgrayprojects.com/synergetics/s09/figs/f86515.html

120 of them, 60 folded left, 60 folded right, all of volume 1/24, make
the volume 5 rhombic triacontahedron.

http://www.rwgrayprojects.com/synergetics/s09/figs/f86419.html

If you blow up the volume by 3/2, to 7.5, the radius becomes phi /
sqrt(2) -- what we're showing with Decimals.

The reason this seems unfamiliar is the unit of volume is the
tetrahedron formed by any four equi-radiused balls in inter-tangency.

I'm spinning this as Martian Math these days, yakking on
math-thinking-l about it, learned it from Bucky Fuller, Dave Koski et
al.

Kirby
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Edu-sig] teaching python using turtle module

2009-11-30 Thread Gregor Lingl

Hello Brian,

I think the most natural use of the if statement (using turtle
graphics) occurs in recursive functions drawing trees,
fractals and the like. This is well known from Logo, where
recursion is the canonical way of doing repetitions. (But
note, that Logo has tail recursion optimizaton!)

If you are not yet ready to use recursion with your students,
probably many  of the problems coming to your mind that need
the examination of conditions  can be solved better by using
a conditional loop (i. e. a while -loop in Python) than by
using mere if statements.

That is not the case however, if you have to perform actions in
the body of a loop, that depend on the current situation.
I did a quick search in my repository of examples and found
a fairly short and simple script that demonstrates, what I mean:
a drunken turtle collecting coins (or whatever) on its random walk.


# Python script using turtle graphics

from turtle import Screen, Turtle
from random import randint

s = Screen()
s.setup(560,560)
s.title("A drunken turtle collecting ...")

s.tracer(False)
writer = Turtle(visible=False)
writer.penup()
writer.goto(0, -275)

coins = []
for i in range(-4,5):
   for j in range(-4, 5):
   if i == j == 0:
   continue
   c = Turtle(shape="circle")
   c.color("", "orange")
   c.shapesize(0.5)
   c.goto(40*i, 40*j)
   coins.append(c)
s.tracer(True)

DRUNKENNESS = 45   
t = Turtle(shape="turtle")

t.color("black","")
points = 0
while abs(t.xcor()) < 200 and abs(t.ycor()) < 200:
   t.forward(5)
   t.right(randint(-DRUNKENNESS, DRUNKENNESS))
   found = None
   for c in coins:
   if t.distance(c) < 10:
   found = c
   break
   if found:
   found.hideturtle()
   coins.remove(found)
   t.shapesize(1+points/5., outline=1+points)
   points += 1

writer.write("{0} points".format(points),
align="center", font=('Arial', 24, 'bold'))

## End of script


You can see a screenshot of a run of this script here:

http://www.dropbox.com/gallery/2016850/1/TurtleCollector?h=6b370a

The script could be expanded in several ways, e. g. for
doing statistical investigations or examinig how the
result depends on different parameters like drunkenness etc.
Or you distribute the coins randomly ... Does that alter
the average "harvest"?

Just a suggestion ...

Regards,
Gregor


Brian Blais schrieb:

Hello,

I was just playing with the turtle module, and thought it was an 
interesting way to augment the introduction to python (I teach college 
students, who haven't had any programming).  It's a great way to 
introduce functions, for-loops, and general program structures.


After a bit of playing, I realized that I couldn't think of many 
examples which use turtle with conditional structures (if- and while- 
statements), or functions that return values, as opposed to 
"procedures" like:


def square(length):
forward(length)
right(90)
forward(length)
right(90)
forward(length)
right(90)
forward(length)
right(90)


If-statements could possibly be used with some sort of random behavior 
(if rand()<0.5 ...).  Are there any other situations, using turtle, 
that these structures would be natural? 




thanks,

Brian Blais

--
Brian Blais
bbl...@bryant.edu <mailto:bbl...@bryant.edu>
http://web.bryant.edu/~bblais <http://web.bryant.edu/%7Ebblais>





___
Edu-sig mailing list
edu-...@python.org
http://mail.python.org/mailman/listinfo/edu-sig
  

--
http://mail.python.org/mailman/listinfo/python-list


Re: [Edu-sig] teaching python using turtle module

2009-11-29 Thread kirby urner
On Sun, Nov 29, 2009 at 2:51 PM, Edward Cherlin  wrote:

<< snip >>

> Drunkard's Walk.
>

If our think tank (isepp.org) could have gotten permission, we'd have
used that Monopoly guy (looks kinda like Planters peanut guy) randomly
walking on like some chess board with a lamp post (reminds of Narnia).
 We don't have that kind of dough though, so just do this conceptually
(conceptual art).

>> Are there any other situations, using turtle, that these
>> structures would be natural?
>
> Recent versions of TA contain stack instructions: push, pop, read,
> clear. Your students might find it interesting to program Forth
> instructions in TA or Python. This has practical applications in
> implementing and porting virtual machines such as Parrot and the VMs
> in Smalltalk and I-APL.
>
> There is plenty more where this came from. You would also be welcome
> to adapt the Python source code for TA tiles to your environment.
>

I recall Alan Kay communicating Seymour Papert's sense that having "an
explicit receiver" was an OK development.  What he meant by that, in
Smalltalk terms, is that the original Logo had what I'd call a
"context turtle" in that FORWARD or RIGHT were w/r to a given Turtle
one didn't need to mention explicitly, like what else could one mean?

With Python and other object oriented implementations, one first gives
birth to a turtle, creates an instance, as in:

>>> someturtle = Turtle()

That's binding a name to a turtle object (giving some turtle object a
name) and then controlling said turtle through the API using dot
notation against the name, e.g. someturtle.forward(10) or
someturtle.right(90).

What you get from this is, of course, the possibility of multiple
turtles, each with its own pen color, visibility, other properties of
self-hood.

This gets showcased in the default demo (in Windows, just double click
on turtle.py in the Lib subdirectory):
http://www.flickr.com/photos/17157...@n00/4145780784/
(using Gregor's 3.1 code just minutes ago)

IronPython also has access to the .NET turtle library:
http://www.flickr.com/photos/mfoord/3104991233/
(not my computer)

I suppose I'm only bringing this up to (a) name drop about being in a
meeting with Alan Kay (with Guido and Mark Shuttleworth among others)
and (b) to remind readers that Logo and turtle art, or the art of
programming with turtles, are orthogonal axes.

Logo as a language has also been extended considerably, as has the
richness of the environment.  Some of these are commercial,
proprietary offerings.

Some of these feature "spatial turtles" in a "turtle tank" i.e. each
turtle is more like a biplane in a WWI dogfight (Snoopy vs. Red
Baron), with all those extra degrees of freedom (roll, pitch, yaw).

Python's turtle module is not, repeat not, an implementation of Logo
in the Python language.  It's an implementation of turtle graphics on
a Tk canvas in the Python language.

You'll also find a turtle module in wxPython such as in PythonCard by
Kevin Altis.
http://pythoncard.sourceforge.net/samples/turtle.html

I think Gregor is right to see turtle.py as an easy way to implement
an Objects First approach, consistent with a more generic approach to
math concepts (vectors, polynomials, polyhedra) as objects (types),
extending the OO rubric.

We teach maths as extensible type systems that advance through the
invention of new types, not just as systems evolving through a
progression of proved theorems from fixed axioms.

Kirby


>> thanks,
>> Brian Blais
>> --
>> Brian Blais
>> bbl...@bryant.edu
>> http://web.bryant.edu/~bblais
>>
>>
>>
>> ___
>> Edu-sig mailing list
>> edu-...@python.org
>> http://mail.python.org/mailman/listinfo/edu-sig
>>
>>
>
>
>
> --
> Edward Mokurai (默雷/धर्ममेघशब्दगर्ज/دھرممیگھشبدگر ج) Cherlin
> Silent Thunder is my name, and Children are my nation.
> The Cosmos is my dwelling place, the Truth my destination.
> http://www.earthtreasury.org/
> ___
> Edu-sig mailing list
> edu-...@python.org
> http://mail.python.org/mailman/listinfo/edu-sig
>



-- 
>>> from mars import math
http://www.wikieducator.org/Martian_Math
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Edu-sig] teaching python using turtle module

2009-11-29 Thread Brian Blais

On Nov 29, 2009, at 17:51 , Edward Cherlin wrote:


If you use the Python-programmable tile in Turtle Art in Sugar, or
Smalltalk in the Turtle Graphics in Etoys, it's even better.


I'll have to check this out.


sequences, where I can use a conditional to stop when the turtle would
go off the screen.


ah, good idea.


or
functions that return values, as opposed to "procedures" like:
def square(length):
forward(length)
right(90)
forward(length)
right(90)
forward(length)
right(90)
forward(length)
right(90)


Surely you mean

repeat(4)
   forward(length)
   right(90)



surely I don't mean.  :)

that's not python.  I'd do:

def square(length):
for i in range(4):
forward(length)
right(90)

but there isn't much difference with such a simple shape.  obviously,  
as one continued, the for-loop method would be clearer.




If-statements could possibly be used with some sort of random  
behavior (if

rand()<0.5 ...).


Drunkard's Walk.



yes, that was the kind of thing I was thinking about.


thanks!

bb


--
Brian Blais
bbl...@bryant.edu
http://web.bryant.edu/~bblais



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Edu-sig] teaching python using turtle module

2009-11-29 Thread Edward Cherlin
On Sun, Nov 29, 2009 at 11:34, Brian Blais  wrote:
> Hello,
> I was just playing with the turtle module, and thought it was an interesting
> way to augment the introduction to python (I teach college students, who
> haven't had any programming).  It's a great way to introduce functions,
> for-loops, and general program structures.

If you use the Python-programmable tile in Turtle Art in Sugar, or
Smalltalk in the Turtle Graphics in Etoys, it's even better. I have
been doing presentations on teaching Python in elementary schools, and
working on how to teach basic Computer Science ideas. You can use an
if-then-else to initialize a stream in Python for the first pass, and
get a value at each pass thereafter. The logic can be either in the TA
or the Python.

> After a bit of playing, I realized that I couldn't think of many exaples
> which use turtle with conditional structures (if- and while- statements),

Repeat is used much more often. but of course we can provide examples
of any behavior you like. I like to use the turtle to generate
sequences, where I can use a conditional to stop when the turtle would
go off the screen. Fibonacci numbers, for example, or exponentials.
Similarly for spirals of various types. Simple cases like those are
easy to do in TA, while more complex sequences could use Python. There
are several fractal examples using loops provided with Sugar on a
Stick, including variations on Siepinksi constructions, and the Koch
Snowflake.

When I can get the code for reading the color of a dot on the screen
into the programmable tile, I can program a toy Turing machine, with
an array of dots as the transition table, and a line of dots as the
tape.

> or
> functions that return values, as opposed to "procedures" like:
> def square(length):
>     forward(length)
>     right(90)
>     forward(length)
>     right(90)
>     forward(length)
>     right(90)
>     forward(length)
>     right(90)

Surely you mean

repeat(4)
   forward(length)
   right(90)

> If-statements could possibly be used with some sort of random behavior (if
> rand()<0.5 ...).

Drunkard's Walk.

> Are there any other situations, using turtle, that these
> structures would be natural?

Recent versions of TA contain stack instructions: push, pop, read,
clear. Your students might find it interesting to program Forth
instructions in TA or Python. This has practical applications in
implementing and porting virtual machines such as Parrot and the VMs
in Smalltalk and I-APL.

There is plenty more where this came from. You would also be welcome
to adapt the Python source code for TA tiles to your environment.

> thanks,
> Brian Blais
> --
> Brian Blais
> bbl...@bryant.edu
> http://web.bryant.edu/~bblais
>
>
>
> ___
> Edu-sig mailing list
> edu-...@python.org
> http://mail.python.org/mailman/listinfo/edu-sig
>
>



-- 
Edward Mokurai (默雷/धर्ममेघशब्दगर्ज/دھرممیگھشبدگر ج) Cherlin
Silent Thunder is my name, and Children are my nation.
The Cosmos is my dwelling place, the Truth my destination.
http://www.earthtreasury.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


teaching python using turtle module

2009-11-29 Thread Brian Blais

Hello,

I was just playing with the turtle module, and thought it was an  
interesting way to augment the introduction to python (I teach  
college students, who haven't had any programming).  It's a great way  
to introduce functions, for-loops, and general program structures.


After a bit of playing, I realized that I couldn't think of many  
examples which use turtle with conditional structures (if- and while-  
statements), or functions that return values, as opposed to  
"procedures" like:


def square(length):
forward(length)
right(90)
forward(length)
right(90)
forward(length)
right(90)
forward(length)
right(90)


If-statements could possibly be used with some sort of random  
behavior (if rand()<0.5 ...).  Are there any other situations, using  
turtle, that these structures would be natural?




thanks,

Brian Blais

--
Brian Blais
bbl...@bryant.edu
http://web.bryant.edu/~bblais



-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: Python's turtle module: collection of examples + demoViewer

2009-08-04 Thread Gregor Lingl

Hi all,

A few days ago I've created a repository of turtle graphics 
demos/applications, that use Python's new turtle module.

You can find it at at google code:

http://python-turtle-demo.googlecode.com

There are two versions of the collection: one for use with Python 3.1
and one for use with Python 2.5 / 2.6. The latter contains a

***  backport of version 1.1 of the turtle module  ***
***  (from Python 3.1) to Python 2.5 / 2.6 *** 



Among others it contains all the examples I have demonstrated
at Pycon 2009 and at EuroPython 2009.

Moreover it contains the demoViewer (which is also in the source
distribution of CPython) that lets you select the examples via a menu,
display their source code and execute them in parallel.

If you are interested to amend some of these examples, add some
explanatory material or contribute additional examples, please tell
me so I could add you as a committer to the project.

I'd be glad to expand the repository whith interesting examples
and applications using the turtle module.

If you have questions concerning the examples, feel free to ask
here or ask me directly via my email-address.

I hope this collection will prove to be useful.

Best regards,
Gregor

P.S.: I tried to announce it at comp.lang.python.announce
but for some unknown reason it was not accepted there


--
http://mail.python.org/mailman/listinfo/python-list