[Edu-sig] suggestions about turtle.py

Vern Ceder vceder at canterburyschool.org
Wed Mar 1 05:18:55 CET 2006


Everyone,

It seems that many of us (probably to our mutual surprise) have use for 
the humble turtle.

I want to get an improved, backward compatible patch into the standard 
package fairly soon, so over the next few days I will see if I can't 
come up with something that covers most of the ideas suggested here, 
including Gregor's libraries to some extent. I will of course post it 
for comments/testing before I send it along.

I would also suggest that those of us who are interested in turtle 
graphics consider what we want (even IF we want) in an extended turtle 
package as well, and how much we would want to push for its inclusion in 
the standard libraries.

My sense is that some of us will be fine if the basic turtle.py is 
usable, but others will really want more. Figuring out the "what" and 
"how much" may take some time. Certainly Gregor's Xturtle package will 
give us some direction in thinking about it.

Cheers,
Vern

Gregor Lingl wrote:
> Vern Ceder schrieb:
> 
>> Hello everyone,
>>
>> As a consequence of my complaining about it in my PyCon talk, I have 
>> been invited to submit some patches for turtle.py. To my mind, 
>> turtle.py should be something that one could actually use for some 
>> very simple "programming with graphics" lessons, with NO tweaking or 
>> additional software.
> 
> 
> Hello all,
> 
> I'm very happy, that this topic is coming up. In my opinion turtle 
> graphics is a very valuable tool for learning (and teaching) 
> programming. That is the reason, why I chose turtle graphics as the 
> basic tool in my textbook "Python für Kids" (written in German), 
> although I felt, that Python's turtle.py was rather limited. In my book 
> I tried (imho successfully) to introduce nearly every programming 
> concept by visualizing it via turtle graphics. Of course there are many 
> other ways to to that, but this is definitely one, which one can go.
> 
> In the meantime (and looking forward to preparing a second edition
> of my book) I've been working on a new turtle graphics module - I named 
> it Xturtle.py.
> 
> My main intention was just to achieve what Vern Ceder wrote in the lines 
> above:
> 
>  > "programming with graphics" lessons, with NO tweaking or additional
>  > software.
> 
> My main inspiration was the turtle graphics component of Logo
> (specifically of MSW-Logo).
> 
> So I'd like to participate in the development of this amended tool.
> 
> What I can offer for now is the following:
> 
> Consider Xturtle.py as a proposition about what a turtle module could
> comprise. So have a look at the functions it provides and at examples
> done with it. It is *NOT* intetended as final result but only as a 
> prototype - but a prototype which had been in use with numerous classes 
> and students since two years and really showed up very few bugs.
> 
> I'm currently doing a complete rewrite, which - in fact - I intended to
> offer to you slready before this thread started up. I think it will take 
> two more intensive coding weekends until I'll come up with a "pre alpha 
> release".
> 
> In the meantime
> 
> 1) I submit my Xturtle.py module along with a set of 10+ demo samples.
> I've zipped them into a package and I'll try to submit them as
> an attachment in a separate follow up posting.
> 
> Moreover the zipped package XturtlePkg.ZIP as well as the single files 
> can be downloaded from
> 
> http://ada.rg16.asn-wien.ac.at/~python/Xturtle/
> 
> The README.TXT, which mainly contains a description of the sample 
> programs, will be attached to this posting.
> 
> Of course I'd like to get feedback from those of you, who find turtle 
> graphics useful for teaching, but ALSO FROM THOSE OF YOU, who "don't 
> think *any* kind of turtle graphics is essential to learning".
> 
> I'd like to stress, that there now is an effort to produce a valuable 
> teaching tool, which should be done as well as possible. Nonwithstanding 
> the fact, that not all who teach Python will use it, nor those, who will 
> use it, will use it in the same way. Moreover let's remember, that 
> turtle graphics was invented to teach programming to very young people.
> So let's do it in a way, that interesting things can easily be done with 
> it.
> 
> 2) When thinking about a renewed turtle.py, there come up a lot of
> points to discuss - especially in the early stage of development.
> (Considering the fact, that here in Europe it's 3:30 in the morning, 
> I'll only will touch a few of them)
> 
> (a) How about compatibility? Should every old turtle program  be 
> executable with the amended module? Remind that there is some
> strange behaviour in the old module concerning fill. IMO it should be 
> discussed if the "radians"-mode in turtle.py should be retained. (Is it 
> really useful?)
> 
> (b) The problem of the "hanging turtle". This was introduced with Python 
> 2.3 when IDLE was renewed. There exist at least to possible "solutions":
> (a) to use IDLE with the -n switch whenever *interactive* turtle 
> graphics is needed. This is rather easy, as opening IDLE for editing a
> given Python program (at least under Windows) opens it automatically in 
> this -n - switch - mode. I for my part work with two different links to
> IDLE on my desktop, normal mode and "no subprocesses" mode, also in my 
> classes.
> (b) one could try to use the approach of John Zelle, which he did in his
> graphics package, namely to let the drawing do in a separate thread. I 
> don't know if this is easily possible with the animated drawing turtles
> - perhaps one should produce a prototype to see ... (Guido two or three 
> years ago told me, that Tkinter is not threadsave)
> (c) I'd propose to add a sort of TurtleCanvas class to the turtle 
> module. (You will observe that Xturtle works with a scrolled canvas due 
> to a comment in the source code of good old turtle.py, which asked for 
> that ;-) ). There are simply several canvas oriented commands (like 
> setbg etc.) To implement them as Pen (= Turtle)  methods doesn't make 
> sense. Also resizing the canvas would be a useful candidate (?).
> (d) I'll add one more question as an example:
> turtle.py has the function width() which sets the thickness of the lines 
> to draw. There is no function to "get" it.
> In Xturtle.py I've implemented pensize() (with width() as an alias) in a 
>  way thatit can be used to set the pensize, when called with an argument 
> and to return the current pensize when called without arguments.
> Would you like this or would you prefer get- and set- functions() for 
> each property? What is the "more pythonic" way?
> There are many functions concerning pen-properties where this problem 
> arises. They should be treated uniformly.
> 
> 
> I'll close for now. Only a few remarks to the following:
> 
>>
>> So I think the following would be handy:
>>
>> 1. equally usable with either "import * from turtle" or "import 
>> turtle" imports
> 
> 
> I think this is possible currently . What do you meadn exactly?
> Something like "from turtle import Pen"?
> 
>> 2. should open with a window covering at least half the screen (the 
>> current default is too small to be useful)
> 
> Xturtle.py does so
> 
>> 3. should offer some simple configuration choices for things like 
>> initial size and shape, but mostly rely on reasonable defaults
> 
> ok, easy to do
> 
>> 4. should offer a class wrapper so that that one could easily 
>> instantiate different turtles for a first experience with objects.
> 
> I don't understand this question. Currently there are the classes
> Pen and RawPen in th turtle module. The anonymous turtle is in fact
> an instance of Pen (named _pen). It is easy to uses several turtles  at 
> the same time.
> 
>> 5. some minor tweaks to make it better behaved when run from IDLE
> 
> I fear, these will become major tweaks ...
> 
>> Does anyone have any feedback on these ideas or any other suggestions 
>> about how turtle.py might be improved without being fundamentally 
>> changed?
>>
>> Note: this is about turtle.py only, for all its deficiencies. Any 
>> suggestions to try another library, system, or language will be 
>> cheerfully, but resolutely, ignored. ;)
> 
> OK - Xturtle uses no other library, system nor language - so please
> do not ignore it - not even resolutely ;-)
> 
> Regards
> Gregor
> 
> P.S.: Xturtle is here, along with its example programs:
> 
> http://ada.rg16.asn-wien.ac.at/~python/Xturtle/
> 
> 
>>
>> Cheers,
>> Vern Ceder
>>
>>
> 
> 
> ------------------------------------------------------------------------
> 
> 
> 2006-03-01
> 
> Xturtle.py is the prototype of a turtle module written in Python.
> It is intended to serve as a first proposition what functions
> and features I consider to be useful in a turtle module and what 
> can easily be done in Python with Tkinter.
> 
> Starting point was the turtle module contained in the current
> Python distribution. To a far extent this eXperimental turtle
> module is compatible with turtle.py. 
> 
> The code is typical experimental. I'm currently doing a complete
> rewrite, which I expect to be in a state of a "pre-alpha-release"
> within about two weeks.
> 
> In the meantime there is much to discuss - see my posting on 
> Python Edu-Sig.
> 
> The Xturtle-package contains
> 
> 1. the Xturtle.py module  (eXperimental turtle module)
> 2. this document - mainly to discribe the
> 3. set of included examples
> 4. A documentation containing a description of (nearly) all 
>    classes and functions contained in the module - written
>    in German language :-(
>    Nevertheless it may be useful for you, as you can see
>    which functions with which parameter-lists are provided.
>    And the function names are English anyway.
>    It is in rtf-format
>    
> (At least I've translated most of the texts occuring in the
> sample programs.)
> 
> =================   
> Important remark!
> =================
> 
> To do interactive turtle-graphics from IDLE, you have to
> run IDLE with the -n-switch (No subprocesses!)
> 
> If you do so, your turtle-graphics programs must not contain
> a mainloop() call.
> 
> There is only one example (Xplotter.py) which I recommend
> to use with IDLE in this way. Interestingly in Windows
> you can achieve this by opening the Python program by 
> right-clicking with the mouse and chosing Edit with IDLE.
> Then press F5 from the active editor - window to run 
> the program. After the program has been run, you can give
> additional graphics-commands from the IDLE shell window,
> if you want and modify the graphics to your liking.
> 
> 
> ===========================================================
> List of example-programs.
> Under Windows you can run them by double-clicking them
> in the windows explorer. Xturtle.py must be on the 
> search path for modules. E.G. in the same directory
> as the examples or in the directory where turtle.py lives.
> ===========================================================
> 
> There are examples from elementary to more elaborated.
> Some of them I used for my teaching, some only to demonstrate
> what can be done with turtle.py
> They are not intended to serve as examples for *optimal*
> solutions. 
> 
> 
> 0. Xturtle.py 
>    has a if __name__== "__main__" demo:
>    So simply start it.
>    First you see the demo from turtle.py to demonstrate
>    compatibility, then you can observe some Xturtle
>    features.
> 
> 1. radioactive.py
>    paints radioactivity-sign
>    if you import turtle instaed of Xturtle, the 
>    program display a subtle bug of turtle.py
>    program essentially written by one of my students
>    
> 2. yinyang.py
>    displays a yin-yang  symbol
>    try also with turtle instead of Xturtle
>    
> 3. Xyinyang.py same as yinyang.py, but uses some (few)
>    features of Xturtle
>    
> 4. sierpinsky.py and Xsierpinsky.py: two coloured 
>    sierpinsky-triangles, one for turtle, the other one
>    for Xturtle
>    
> 5. Xcurlicues.py display three of the curlicues described
>    by Ian Stuart in his book "Another Fine Math You've Got 
>    Me Into ..." --- very well suited for turtle graphics.    
>    After the third graphic has been displayed, shut the
>    graphics window.
>    (The third one can only be generated thus easily with
>    a language with long integer arithmetics.)
>    
> 6. Xtree.py displays a typical binary tree as done so often
>    with turtle graphics, BUT this time done with a
>    Python generator. As a result the tree is displayed
>    the breadth-first-way. 
>    
> 7. Xforest.py  elaborates the idea from 6.
> 
> 8. Xhangman.py This is from my book "Python für Kids" - 
>    only turtle replaced by Xturtle.  Compatibility-check.
>    (You can do the reverse and see, that it also runs
>    with turtle.py)
>    
> 9. Xmoorhuhn.py is a well known action game. Uses three
>    gifs contained in the directory. Only for people 
>    accustomed to this type of games. (I normally achieve
>    a hit rate of 0.25 :-( )
>    
> 10. Xgame2 is a very strange game, which I invented for demo
>     purposes. It is an event driven program for two players.
>     There are two turtles on the screen. One of them is 
>     governed by mouseclicks (left, middle, right),
>     the other one by keypresses (arrow-keys: left/up/right) 
>     One of them is red (the hunter), the other one - blue - is 
>     the prey (i.e. to be cought). The role of the turtles
>     - and accordingly their color - changes randomly. 
>     So while it's fin to be far away, if you are hunted, it's
>     not so fine if you suddenly become the hunter ....
>     
> 11. Xspaceship is intended as a learning game.
>     There is a spaceship in space without gravity.
>     It has to be led to a target by simulated rocket
>     propulsion. Start the game and again use three
>     arrow-keys to move it around. But be aware, that
>     you only can stop it by turning it 180 degrees and
>     "accelerate" it in the opposite direction ....
>     Students like it ...
> 
> 12. mill1.py   - doubleclick and look. A very simple
>     animation.
>     
>     mill2.py   - doubleclick and look. Another animation.
>                  Wait a little, it will develop differently.
>                  
>     These two programs use an experimental feature, which is 
>     not documented: userdefined turtle-shapes.     
> 
> ==================================================
> 
> 13. Xplotter.py  === USE THIS IN INTERACTIVE MODE
>     e.g. by rightclicking and chosing Edit with IDLE.
>     
>     run it. It is intended to show the relation 
>     between a function and its derivative.
>     
>     Click several times into the graphics window.
>     If you have learned enough about the graphs shown
>     type
>     
>     >>> plot(fun, -1, 2.5)
>     
>     (there is a function fun defined in the script)
>     
>     or define and display your own functions (along with
>     their derivatives)
>     
> ===================================================    
> 
> 
> 
> 
>       
>    

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


More information about the Edu-sig mailing list