| 1 |
|
|---|
| 2 | ========================================================
|
|---|
| 3 | A new turtle module for Python
|
|---|
| 4 | ========================================================
|
|---|
| 5 |
|
|---|
| 6 | Turtle graphics is a popular way for introducing programming to
|
|---|
| 7 | kids. It was part of the original Logo programming language developed
|
|---|
| 8 | by Wally Feurzig and Seymour Papert in 1966.
|
|---|
| 9 |
|
|---|
| 10 | Imagine a robotic turtle starting at (0, 0) in the x-y plane. After an ``import turtle``, give it
|
|---|
| 11 | the command turtle.forward(15), and it moves (on-screen!) 15 pixels in
|
|---|
| 12 | the direction it is facing, drawing a line as it moves. Give it the
|
|---|
| 13 | command turtle.right(25), and it rotates in-place 25 degrees clockwise.
|
|---|
| 14 |
|
|---|
| 15 | By combining together these and similar commands, intricate shapes and
|
|---|
| 16 | pictures can easily be drawn.
|
|---|
| 17 |
|
|---|
| 18 | ----- turtle.py
|
|---|
| 19 |
|
|---|
| 20 | This module is an extended reimplementation of turtle.py from the
|
|---|
| 21 | Python standard distribution up to Python 2.5. (See: http:\\www.python.org)
|
|---|
| 22 |
|
|---|
| 23 | It tries to keep the merits of turtle.py and to be (nearly) 100%
|
|---|
| 24 | compatible with it. This means in the first place to enable the
|
|---|
| 25 | learning programmer to use all the commands, classes and methods
|
|---|
| 26 | interactively when using the module from within IDLE run with
|
|---|
| 27 | the -n switch.
|
|---|
| 28 |
|
|---|
| 29 | Roughly it has the following features added:
|
|---|
| 30 |
|
|---|
| 31 | - Better animation of the turtle movements, especially of turning the
|
|---|
| 32 | turtle. So the turtles can more easily be used as a visual feedback
|
|---|
| 33 | instrument by the (beginning) programmer.
|
|---|
| 34 |
|
|---|
| 35 | - Different turtle shapes, gif-images as turtle shapes, user defined
|
|---|
| 36 | and user controllable turtle shapes, among them compound
|
|---|
| 37 | (multicolored) shapes. Turtle shapes can be stgretched and tilted, which
|
|---|
| 38 | makes turtles zu very versatile geometrical objects.
|
|---|
| 39 |
|
|---|
| 40 | - Fine control over turtle movement and screen updates via delay(),
|
|---|
| 41 | and enhanced tracer() and speed() methods.
|
|---|
| 42 |
|
|---|
| 43 | - Aliases for the most commonly used commands, like fd for forward etc.,
|
|---|
| 44 | following the early Logo traditions. This reduces the boring work of
|
|---|
| 45 | typing long sequences of commands, which often occur in a natural way
|
|---|
| 46 | when kids try to program fancy pictures on their first encounter with
|
|---|
| 47 | turtle graphcis.
|
|---|
| 48 |
|
|---|
| 49 | - Turtles now have an undo()-method with configurable undo-buffer.
|
|---|
| 50 |
|
|---|
| 51 | - Some simple commands/methods for creating event driven programs
|
|---|
| 52 | (mouse-, key-, timer-events). Especially useful for programming games.
|
|---|
| 53 |
|
|---|
| 54 | - A scrollable Canvas class. The default scrollable Canvas can be
|
|---|
| 55 | extended interactively as needed while playing around with the turtle(s).
|
|---|
| 56 |
|
|---|
| 57 | - A TurtleScreen class with methods controlling background color or
|
|---|
| 58 | background image, window and canvas size and other properties of the
|
|---|
| 59 | TurtleScreen.
|
|---|
| 60 |
|
|---|
| 61 | - There is a method, setworldcoordinates(), to install a user defined
|
|---|
| 62 | coordinate-system for the TurtleScreen.
|
|---|
| 63 |
|
|---|
| 64 | - The implementation uses a 2-vector class named Vec2D, derived from tuple.
|
|---|
| 65 | This class is public, so it can be imported by the application programmer,
|
|---|
| 66 | which makes certain types of computations very natural and compact.
|
|---|
| 67 |
|
|---|
| 68 | - Appearance of the TurtleScreen and the Turtles at startup/import can be
|
|---|
| 69 | configured by means of a turtle.cfg configuration file.
|
|---|
| 70 | The default configuration mimics the appearance of the old turtle module.
|
|---|
| 71 |
|
|---|
| 72 | - If configured appropriately the module reads in docstrings from a docstring
|
|---|
| 73 | dictionary in some different language, supplied separately and replaces
|
|---|
| 74 | the english ones by those read in. There is a utility function
|
|---|
| 75 | write_docstringdict() to write a dictionary with the original (english)
|
|---|
| 76 | docstrings to disc, so it can serve as a template for translations.
|
|---|
| 77 |
|
|---|