Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 55e9396

Browse files
committed
Preliminary documentation for turtle module (Tk), by Moshe Zadka.
Fixed up a few TeXisms and markup nits, but otherwise unchanged. Somewhat raw.
1 parent 77980a7 commit 55e9396

1 file changed

Lines changed: 160 additions & 0 deletions

File tree

Doc/lib/libturtle.tex

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
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+
12+
The \module{turtle} module provides turtle graphics primitives, in both an
13+
object-oriented and procedure-oriented ways. Because it uses \module{Tkinter}
14+
for the underlying graphics, it needs a version of python installed with
15+
Tk support.
16+
17+
The procedural interface uses a pen and a canvas which are automagically
18+
created when any of the functions are called.
19+
20+
The \module{turtle} module defines the following functions:
21+
22+
\begin{funcdesc}{degrees}{}
23+
Set angle measurement units to degrees.
24+
\end{funcdesc}
25+
26+
\begin{funcdesc}{radians}{}
27+
Set angle measurement units to radians.
28+
\end{funcdesc}
29+
30+
\begin{funcdesc}{reset}{}
31+
Clear the screen, re-center the pen, and set variables to the default
32+
values.
33+
\end{funcdesc}
34+
35+
\begin{funcdesc}{clear}{}
36+
Clear the screen.
37+
\end{funcdesc}
38+
39+
\begin{funcdesc}{tracer}{flag}
40+
Set tracing on/off (according to whether flag is true or not). Tracing
41+
means line are drawn more slowly, with an animation of an arrow along the
42+
line.
43+
\end{funcdesc}
44+
45+
\begin{funcdesc}{forward}{distance}
46+
Go forward \var{distance} steps.
47+
\end{funcdesc}
48+
49+
\begin{funcdesc}{backward}{distance}
50+
Go backward \var{distance} steps.
51+
\end{funcdesc}
52+
53+
\begin{funcdesc}{left}{angle}
54+
Turn left \var{angle} units. Units are by default degrees, but can be
55+
set via the \function{degrees()} and \function{radians()} functions.
56+
\end{funcdesc}
57+
58+
\begin{funcdesc}{right}{angle}
59+
Turn right \var{angle} units. Units are by default degrees, but can be
60+
set via the \function{degrees()} and \function{radians()} functions.
61+
\end{funcdesc}
62+
63+
\begin{funcdesc}{up}{}
64+
Move the pen up --- stop drawing.
65+
\end{funcdesc}
66+
67+
\begin{funcdesc}{down}{}
68+
Move the pen up --- draw when moving.
69+
\end{funcdesc}
70+
71+
\begin{funcdesc}{width}{width}
72+
Set the line width to \var{width}.
73+
\end{funcdesc}
74+
75+
\begin{funcdesc}{color}{s}
76+
Set the color by giving a Tk color string.
77+
\end{funcdesc}
78+
79+
\begin{funcdesc}{color}{(r, g, b)}
80+
Set the color by giving a RGB tuple, each between 0 and 1.
81+
\end{funcdesc}
82+
83+
\begin{funcdesc}{color}{r, g, b}
84+
Set the color by giving the RGB components, each between 0 and 1.
85+
\end{funcdesc}
86+
87+
\begin{funcdesc}{write}{text\optional{, move}}
88+
Write \var{text} at the current pen position. If \var{move} is true,
89+
the pen is moved to the bottom-right corner of the text. By default,
90+
\var{move} is false.
91+
\end{funcdesc}
92+
93+
\begin{funcdesc}{fill}{flag}
94+
The complete specifications are rather complex, but the recommended
95+
usage is: call \code{fill(1)} before drawing a path you want to fill,
96+
and call \code{fill(0)} when you finish to draw the path.
97+
\end{funcdesc}
98+
99+
\begin{funcdesc}{circle}{radius\optional{, extent}}
100+
Draw a circle with radius \var{radius} whose center-point is where the
101+
pen would be if a \code{forward(\var{radius})} were
102+
called. \var{extent} determines which part of a circle is drawn: if
103+
not given it defaults to a full circle.
104+
105+
If \var{extent} is not a full circle, one endpoint of the arc is the
106+
current pen position. The arc is drawn in a counter clockwise
107+
direction if \var{radius} is positive, otherwise in a clockwise
108+
direction.
109+
\end{funcdesc}
110+
111+
\begin{funcdesc}{goto}{x, y}
112+
Go to co-ordinates (\var{x}, \var{y}).
113+
\end{funcdesc}
114+
115+
\begin{funcdesc}{goto}{(x, y)}
116+
Go to co-ordinates (\var{x}, \var{y}) (specified as a tuple instead of
117+
individually).
118+
\end{funcdesc}
119+
120+
This module also does a documented \code{from math import *}, so see
121+
the documentation for the \refmodule{math} module for additional
122+
constants and functions useful for turtle graphics.
123+
% XXX Should we mention this? If so, a \seealso is also in place...
124+
125+
\begin{funcdesc}{demo}{}
126+
Exercise the module a bit.
127+
\end{funcdesc}
128+
129+
\begin{excdesc}{Error}
130+
Exception raised on any error caught by this module.
131+
\end{excdesc}
132+
133+
For examples, see the code of the \function{demo()} function.
134+
135+
This module defines the following classes:
136+
137+
\begin{classdesc}{Pen}{}
138+
Define a pen. All above functions can be called as a methods on the given
139+
pen. The constructor automatically creates a canvas do be drawn on.
140+
\end{classdesc}
141+
142+
\begin{classdesc}{RawPen}{canvas}
143+
Define a pen which draws on a canvas \var{canvas}. This is useful if
144+
you want to use the module to create graphics in a ``real'' program.
145+
\end{classdesc}
146+
147+
\subsection{Pen and RawPen Objects \label{pen-rawpen-objects}}
148+
149+
\class{Pen} and \class{RawPen} objects have all the global functions
150+
described above, except for \function{demo()} as methods, which
151+
manipulate the given pen.
152+
153+
The only method which is more powerful as a method is
154+
\function{degrees()}.
155+
156+
\begin{methoddesc}{degrees}{\optional{fullcircle}}
157+
\var{fullcircle} is by default 360. This can cause the pen to have any
158+
angular units whatever: give \var{fullcircle} 2*$\pi$ for radians, or
159+
400 for gradians.
160+
\end{methoddesc}

0 commit comments

Comments
 (0)