source: trunk/essentials/dev-lang/python/Doc/lib/libturtle.tex@ 3368

Last change on this file since 3368 was 3225, checked in by bird, 19 years ago

Python 2.5

File size: 8.2 KB
Line 
1\section{\module{turtle} ---
2 Turtle graphics for Tk}
3
4\declaremodule{standard}{turtle}
5 \platform{Tk}
6\moduleauthor{Guido van Rossum}{[email protected]}
7\modulesynopsis{An environment for turtle graphics.}
8
9\sectionauthor{Moshe Zadka}{[email protected]}
10
11
12The \module{turtle} module provides turtle graphics primitives, in both an
13object-oriented and procedure-oriented ways. Because it uses \module{Tkinter}
14for the underlying graphics, it needs a version of python installed with
15Tk support.
16
17The procedural interface uses a pen and a canvas which are automagically
18created when any of the functions are called.
19
20The \module{turtle} module defines the following functions:
21
22\begin{funcdesc}{degrees}{}
23Set angle measurement units to degrees.
24\end{funcdesc}
25
26\begin{funcdesc}{radians}{}
27Set angle measurement units to radians.
28\end{funcdesc}
29
30\begin{funcdesc}{setup}{**kwargs}
31Sets the size and position of the main window. Keywords are:
32\begin{itemize}
33 \item \code{width}: either a size in pixels or a fraction of the screen.
34 The default is 50\% of the screen.
35 \item \code{height}: either a size in pixels or a fraction of the screen.
36 The default is 50\% of the screen.
37 \item \code{startx}: starting position in pixels from the left edge
38 of the screen. \code{None} is the default value and
39 centers the window horizontally on screen.
40 \item \code{starty}: starting position in pixels from the top edge
41 of the screen. \code{None} is the default value and
42 centers the window vertically on screen.
43\end{itemize}
44
45 Examples:
46
47\begin{verbatim}
48# Uses default geometry: 50% x 50% of screen, centered.
49setup()
50
51# Sets window to 200x200 pixels, in upper left of screen
52setup (width=200, height=200, startx=0, starty=0)
53
54# Sets window to 75% of screen by 50% of screen, and centers it.
55setup(width=.75, height=0.5, startx=None, starty=None)
56\end{verbatim}
57
58\end{funcdesc}
59
60\begin{funcdesc}{title}{title_str}
61Set the window's title to \var{title}.
62\end{funcdesc}
63
64\begin{funcdesc}{done}{}
65Enters the Tk main loop. The window will continue to
66be displayed until the user closes it or the process is killed.
67\end{funcdesc}
68
69\begin{funcdesc}{reset}{}
70Clear the screen, re-center the pen, and set variables to the default
71values.
72\end{funcdesc}
73
74\begin{funcdesc}{clear}{}
75Clear the screen.
76\end{funcdesc}
77
78\begin{funcdesc}{tracer}{flag}
79Set tracing on/off (according to whether flag is true or not). Tracing
80means line are drawn more slowly, with an animation of an arrow along the
81line.
82\end{funcdesc}
83
84\begin{funcdesc}{speed}{speed}
85Set the speed of the turtle. Valid values for the parameter
86\var{speed} are \code{'fastest'} (no delay), \code{'fast'},
87(delay 5ms), \code{'normal'} (delay 10ms), \code{'slow'}
88(delay 15ms), and \code{'slowest'} (delay 20ms).
89\versionadded{2.5}
90\end{funcdesc}
91
92\begin{funcdesc}{delay}{delay}
93Set the speed of the turtle to \var{delay}, which is given
94in ms. \versionadded{2.5}
95\end{funcdesc}
96
97\begin{funcdesc}{forward}{distance}
98Go forward \var{distance} steps.
99\end{funcdesc}
100
101\begin{funcdesc}{backward}{distance}
102Go backward \var{distance} steps.
103\end{funcdesc}
104
105\begin{funcdesc}{left}{angle}
106Turn left \var{angle} units. Units are by default degrees, but can be
107set via the \function{degrees()} and \function{radians()} functions.
108\end{funcdesc}
109
110\begin{funcdesc}{right}{angle}
111Turn right \var{angle} units. Units are by default degrees, but can be
112set via the \function{degrees()} and \function{radians()} functions.
113\end{funcdesc}
114
115\begin{funcdesc}{up}{}
116Move the pen up --- stop drawing.
117\end{funcdesc}
118
119\begin{funcdesc}{down}{}
120Move the pen down --- draw when moving.
121\end{funcdesc}
122
123\begin{funcdesc}{width}{width}
124Set the line width to \var{width}.
125\end{funcdesc}
126
127\begin{funcdesc}{color}{s}
128\funclineni{color}{(r, g, b)}
129\funclineni{color}{r, g, b}
130Set the pen color. In the first form, the color is specified as a
131Tk color specification as a string. The second form specifies the
132color as a tuple of the RGB values, each in the range [0..1]. For the
133third form, the color is specified giving the RGB values as three
134separate parameters (each in the range [0..1]).
135\end{funcdesc}
136
137\begin{funcdesc}{write}{text\optional{, move}}
138Write \var{text} at the current pen position. If \var{move} is true,
139the pen is moved to the bottom-right corner of the text. By default,
140\var{move} is false.
141\end{funcdesc}
142
143\begin{funcdesc}{fill}{flag}
144The complete specifications are rather complex, but the recommended
145usage is: call \code{fill(1)} before drawing a path you want to fill,
146and call \code{fill(0)} when you finish to draw the path.
147\end{funcdesc}
148
149\begin{funcdesc}{begin\_fill}{}
150Switch turtle into filling mode;
151Must eventually be followed by a corresponding end_fill() call.