Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v9 / html / python / lib / module-turtle.html
CommitLineData
920dae64
AT
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<html>
3<head>
4<link rel="STYLESHEET" href="lib.css" type='text/css' />
5<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
6<link rel='start' href='../index.html' title='Python Documentation Index' />
7<link rel="first" href="lib.html" title='Python Library Reference' />
8<link rel='contents' href='contents.html' title="Contents" />
9<link rel='index' href='genindex.html' title='Index' />
10<link rel='last' href='about.html' title='About this document...' />
11<link rel='help' href='about.html' title='About this document...' />
12<link rel="next" href="idle.html" />
13<link rel="prev" href="module-ScrolledText.html" />
14<link rel="parent" href="tkinter.html" />
15<link rel="next" href="pen-rawpen-objects.html" />
16<meta name='aesop' content='information' />
17<title>16.4 turtle -- Turtle graphics for Tk</title>
18</head>
19<body>
20<DIV CLASS="navigation">
21<div id='top-navigation-panel' xml:id='top-navigation-panel'>
22<table align="center" width="100%" cellpadding="0" cellspacing="2">
23<tr>
24<td class='online-navigation'><a rel="prev" title="16.3 ScrolledText "
25 href="module-ScrolledText.html"><img src='../icons/previous.png'
26 border='0' height='32' alt='Previous Page' width='32' /></A></td>
27<td class='online-navigation'><a rel="parent" title="16. Graphical User Interfaces"
28 href="tkinter.html"><img src='../icons/up.png'
29 border='0' height='32' alt='Up One Level' width='32' /></A></td>
30<td class='online-navigation'><a rel="next" title="16.4.1 Pen and RawPen"
31 href="pen-rawpen-objects.html"><img src='../icons/next.png'
32 border='0' height='32' alt='Next Page' width='32' /></A></td>
33<td align="center" width="100%">Python Library Reference</td>
34<td class='online-navigation'><a rel="contents" title="Table of Contents"
35 href="contents.html"><img src='../icons/contents.png'
36 border='0' height='32' alt='Contents' width='32' /></A></td>
37<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
38 border='0' height='32' alt='Module Index' width='32' /></a></td>
39<td class='online-navigation'><a rel="index" title="Index"
40 href="genindex.html"><img src='../icons/index.png'
41 border='0' height='32' alt='Index' width='32' /></A></td>
42</tr></table>
43<div class='online-navigation'>
44<b class="navlabel">Previous:</b>
45<a class="sectref" rel="prev" href="module-ScrolledText.html">16.3 ScrolledText </A>
46<b class="navlabel">Up:</b>
47<a class="sectref" rel="parent" href="tkinter.html">16. Graphical User Interfaces</A>
48<b class="navlabel">Next:</b>
49<a class="sectref" rel="next" href="pen-rawpen-objects.html">16.4.1 Pen and RawPen</A>
50</div>
51<hr /></div>
52</DIV>
53<!--End of Navigation Panel-->
54
55<H1><A NAME="SECTION0018400000000000000000">
5616.4 <tt class="module">turtle</tt> --
57 Turtle graphics for Tk</A>
58</H1>
59
60<P>
61<A NAME="module-turtle"></A>
62<p class="availability">Availability: <span
63 class="platform">Tk</span>.</p>
64
65<P>
66
67<P>
68The <tt class="module">turtle</tt> module provides turtle graphics primitives, in both an
69object-oriented and procedure-oriented ways. Because it uses <tt class="module">Tkinter</tt>
70for the underlying graphics, it needs a version of python installed with
71Tk support.
72
73<P>
74The procedural interface uses a pen and a canvas which are automagically
75created when any of the functions are called.
76
77<P>
78The <tt class="module">turtle</tt> module defines the following functions:
79
80<P>
81<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
82 <td><nobr><b><tt id='l2h-4885' xml:id='l2h-4885' class="function">degrees</tt></b>(</nobr></td>
83 <td><var></var>)</td></tr></table></dt>
84<dd>
85Set angle measurement units to degrees.
86</dl>
87
88<P>
89<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
90 <td><nobr><b><tt id='l2h-4886' xml:id='l2h-4886' class="function">radians</tt></b>(</nobr></td>
91 <td><var></var>)</td></tr></table></dt>
92<dd>
93Set angle measurement units to radians.
94</dl>
95
96<P>
97<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
98 <td><nobr><b><tt id='l2h-4887' xml:id='l2h-4887' class="function">reset</tt></b>(</nobr></td>
99 <td><var></var>)</td></tr></table></dt>
100<dd>
101Clear the screen, re-center the pen, and set variables to the default
102values.
103</dl>
104
105<P>
106<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
107 <td><nobr><b><tt id='l2h-4888' xml:id='l2h-4888' class="function">clear</tt></b>(</nobr></td>
108 <td><var></var>)</td></tr></table></dt>
109<dd>
110Clear the screen.
111</dl>
112
113<P>
114<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
115 <td><nobr><b><tt id='l2h-4889' xml:id='l2h-4889' class="function">tracer</tt></b>(</nobr></td>
116 <td><var>flag</var>)</td></tr></table></dt>
117<dd>
118Set tracing on/off (according to whether flag is true or not). Tracing
119means line are drawn more slowly, with an animation of an arrow along the
120line.
121</dl>
122
123<P>
124<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
125 <td><nobr><b><tt id='l2h-4890' xml:id='l2h-4890' class="function">forward</tt></b>(</nobr></td>
126 <td><var>distance</var>)</td></tr></table></dt>
127<dd>
128Go forward <var>distance</var> steps.
129</dl>
130
131<P>
132<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
133 <td><nobr><b><tt id='l2h-4891' xml:id='l2h-4891' class="function">backward</tt></b>(</nobr></td>
134 <td><var>distance</var>)</td></tr></table></dt>
135<dd>
136Go backward <var>distance</var> steps.
137</dl>
138
139<P>
140<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
141 <td><nobr><b><tt id='l2h-4892' xml:id='l2h-4892' class="function">left</tt></b>(</nobr></td>
142 <td><var>angle</var>)</td></tr></table></dt>
143<dd>
144Turn left <var>angle</var> units. Units are by default degrees, but can be
145set via the <tt class="function">degrees()</tt> and <tt class="function">radians()</tt> functions.
146</dl>
147
148<P>
149<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
150 <td><nobr><b><tt id='l2h-4893' xml:id='l2h-4893' class="function">right</tt></b>(</nobr></td>
151 <td><var>angle</var>)</td></tr></table></dt>
152<dd>
153Turn right <var>angle</var> units. Units are by default degrees, but can be
154set via the <tt class="function">degrees()</tt> and <tt class="function">radians()</tt> functions.
155</dl>
156
157<P>
158<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
159 <td><nobr><b><tt id='l2h-4894' xml:id='l2h-4894' class="function">up</tt></b>(</nobr></td>
160 <td><var></var>)</td></tr></table></dt>
161<dd>
162Move the pen up -- stop drawing.
163</dl>
164
165<P>
166<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
167 <td><nobr><b><tt id='l2h-4895' xml:id='l2h-4895' class="function">down</tt></b>(</nobr></td>
168 <td><var></var>)</td></tr></table></dt>
169<dd>
170Move the pen down -- draw when moving.
171</dl>
172
173<P>
174<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
175 <td><nobr><b><tt id='l2h-4896' xml:id='l2h-4896' class="function">width</tt></b>(</nobr></td>
176 <td><var>width</var>)</td></tr></table></dt>
177<dd>
178Set the line width to <var>width</var>.
179</dl>
180
181<P>
182<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
183 <td><nobr><b><tt id='l2h-4897' xml:id='l2h-4897' class="function">color</tt></b>(</nobr></td>
184 <td><var>s</var>)</td></tr></table></dt>
185<dd>
186<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
187 <td><nobr><b><tt class="function">color</tt></b>(</nobr></td>
188 <td><var>(r, g, b)</var>)</td></tr></table></dt>
189<dd><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
190 <td><nobr><b><tt class="function">color</tt></b>(</nobr></td>
191 <td><var>r, g, b</var>)</td></tr></table></dt>
192<dd>Set the pen color. In the first form, the color is specified as a
193Tk color specification as a string. The second form specifies the
194color as a tuple of the RGB values, each in the range [0..1]. For the
195third form, the color is specified giving the RGB values as three
196separate parameters (each in the range [0..1]).
197</dl>
198
199<P>
200<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
201 <td><nobr><b><tt id='l2h-4898' xml:id='l2h-4898' class="function">write</tt></b>(</nobr></td>
202 <td><var>text</var><big>[</big><var>, move</var><big>]</big><var></var>)</td></tr></table></dt>
203<dd>
204Write <var>text</var> at the current pen position. If <var>move</var> is true,
205the pen is moved to the bottom-right corner of the text. By default,
206<var>move</var> is false.
207</dl>
208
209<P>
210<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
211 <td><nobr><b><tt id='l2h-4899' xml:id='l2h-4899' class="function">fill</tt></b>(</nobr></td>
212 <td><var>flag</var>)</td></tr></table></dt>
213<dd>
214The complete specifications are rather complex, but the recommended
215usage is: call <code>fill(1)</code> before drawing a path you want to fill,
216and call <code>fill(0)</code> when you finish to draw the path.
217</dl>
218
219<P>
220<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
221 <td><nobr><b><tt id='l2h-4900' xml:id='l2h-4900' class="function">circle</tt></b>(</nobr></td>
222 <td><var>radius</var><big>[</big><var>, extent</var><big>]</big><var></var>)</td></tr></table></dt>
223<dd>
224Draw a circle with radius <var>radius</var> whose center-point is
225<var>radius</var> units left of the turtle.
226<var>extent</var> determines which part of a circle is drawn: if
227not given it defaults to a full circle.
228
229<P>
230If <var>extent</var> is not a full circle, one endpoint of the arc is the
231current pen position. The arc is drawn in a counter clockwise
232direction if <var>radius</var> is positive, otherwise in a clockwise
233direction. In the process, the direction of the turtle is changed
234by the amount of the <var>extent</var>.
235</dl>
236
237<P>
238<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
239 <td><nobr><b><tt id='l2h-4901' xml:id='l2h-4901' class="function">goto</tt></b>(</nobr></td>
240 <td><var>x, y</var>)</td></tr></table></dt>
241<dd>
242<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
243 <td><nobr><b><tt class="function">goto</tt></b>(</nobr></td>
244 <td><var>(x, y)</var>)</td></tr></table></dt>
245<dd>Go to co-ordinates <var>x</var>, <var>y</var>. The co-ordinates may be
246specified either as two separate arguments or as a 2-tuple.
247</dl>
248
249<P>
250This module also does <code>from math import *</code>, so see the
251documentation for the <tt class="module"><a href="module-math.html">math</a></tt> module for additional constants
252and functions useful for turtle graphics.
253
254<P>
255<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
256 <td><nobr><b><tt id='l2h-4902' xml:id='l2h-4902' class="function">demo</tt></b>(</nobr></td>
257 <td><var></var>)</td></tr></table></dt>
258<dd>
259Exercise the module a bit.
260</dl>
261
262<P>
263<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-4903' xml:id='l2h-4903' class="exception">Error</tt></b></dt>
264<dd>
265Exception raised on any error caught by this module.
266</dd></dl>
267
268<P>
269For examples, see the code of the <tt class="function">demo()</tt> function.
270
271<P>
272This module defines the following classes:
273
274<P>
275<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
276 <td><nobr><b><span class="typelabel">class</span>&nbsp;<tt id='l2h-4904' xml:id='l2h-4904' class="class">Pen</tt></b>(</nobr></td>
277 <td><var></var>)</td></tr></table></dt>
278<dd>
279Define a pen. All above functions can be called as a methods on the given
280pen. The constructor automatically creates a canvas do be drawn on.
281</dl>
282
283<P>
284<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
285 <td><nobr><b><span class="typelabel">class</span>&nbsp;<tt id='l2h-4905' xml:id='l2h-4905' class="class">RawPen</tt></b>(</nobr></td>
286 <td><var>canvas</var>)</td></tr></table></dt>
287<dd>
288Define a pen which draws on a canvas <var>canvas</var>. This is useful if
289you want to use the module to create graphics in a ``real'' program.
290</dl>
291
292<P>
293
294<p><br /></p><hr class='online-navigation' />
295<div class='online-navigation'>
296<!--Table of Child-Links-->
297<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></a>
298
299<UL CLASS="ChildLinks">
300<LI><A href="pen-rawpen-objects.html">16.4.1 Pen and RawPen Objects</a>
301</ul>
302<!--End of Table of Child-Links-->
303</div>
304
305<DIV CLASS="navigation">
306<div class='online-navigation'>
307<p></p><hr />
308<table align="center" width="100%" cellpadding="0" cellspacing="2">
309<tr>
310<td class='online-navigation'><a rel="prev" title="16.3 ScrolledText "
311 href="module-ScrolledText.html"><img src='../icons/previous.png'
312 border='0' height='32' alt='Previous Page' width='32' /></A></td>
313<td class='online-navigation'><a rel="parent" title="16. Graphical User Interfaces"
314 href="tkinter.html"><img src='../icons/up.png'
315 border='0' height='32' alt='Up One Level' width='32' /></A></td>
316<td class='online-navigation'><a rel="next" title="16.4.1 Pen and RawPen"
317 href="pen-rawpen-objects.html"><img src='../icons/next.png'
318 border='0' height='32' alt='Next Page' width='32' /></A></td>
319<td align="center" width="100%">Python Library Reference</td>
320<td class='online-navigation'><a rel="contents" title="Table of Contents"
321 href="contents.html"><img src='../icons/contents.png'
322 border='0' height='32' alt='Contents' width='32' /></A></td>
323<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
324 border='0' height='32' alt='Module Index' width='32' /></a></td>
325<td class='online-navigation'><a rel="index" title="Index"
326 href="genindex.html"><img src='../icons/index.png'
327 border='0' height='32' alt='Index' width='32' /></A></td>
328</tr></table>
329<div class='online-navigation'>
330<b class="navlabel">Previous:</b>
331<a class="sectref" rel="prev" href="module-ScrolledText.html">16.3 ScrolledText </A>
332<b class="navlabel">Up:</b>
333<a class="sectref" rel="parent" href="tkinter.html">16. Graphical User Interfaces</A>
334<b class="navlabel">Next:</b>
335<a class="sectref" rel="next" href="pen-rawpen-objects.html">16.4.1 Pen and RawPen</A>
336</div>
337</div>
338<hr />
339<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
340</DIV>
341<!--End of Navigation Panel-->
342<ADDRESS>
343See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
344</ADDRESS>
345</BODY>
346</HTML>