You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: en/_sources/simple_drawing.txt
+35-15Lines changed: 35 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -9,24 +9,32 @@ Turtle is like a drawing board.
9
9
It has functions like ``turtle.forward(...)`` and ``turtle.left(...)`` which
10
10
can move the turtle around.
11
11
12
-
Before you can use turtle, you have to import it (we'd recommend playing around
13
-
with it in the interactive interpreter first, there is an extra bit of work
14
-
required to make it work from files)::
12
+
Before you can use turtle, you have to import it. We recommend playing around
13
+
with it in the interactive interpreter first, as there is an extra bit of work
14
+
required to make it work from files. Just go to your terminal and type::
15
15
16
16
import turtle
17
17
18
18
.. image:: /images/default.png
19
19
20
20
.. note::
21
21
22
-
Not seeing anything on Mac OS? Try looking if a new window opened behind
23
-
your command line.
22
+
Not seeing anything on Mac OS? Try issuing a command like
23
+
``turtle.forward(0)`` and looking if a new window opened behind your
24
+
command line.
24
25
25
26
.. note::
26
27
27
28
Do you work with Ubuntu and get the error message "No module named
28
29
_tkinter"? Install the missing package with ``sudo apt-get install
29
-
python-tk``
30
+
python3-tk``
31
+
32
+
.. note::
33
+
34
+
While it might be tempting to just copy and paste what's written on
35
+
this page into your terminal, we encourage you to type out each command.
36
+
Typing gets the syntax under your fingers (building that muscle memory!)
37
+
and can even help avoid strange syntax errors.
30
38
31
39
::
32
40
@@ -42,9 +50,14 @@ required to make it work from files)::
42
50
43
51
44
52
The ``turtle.forward(...)`` function tells the turtle to move forward
45
-
by the given distance. ``turtle.left(...)`` takes a number of degrees which you want
46
-
to rotate to the left. (There are ``turtle.backward(...)`` and
47
-
``turtle.right(...)``, too.)
53
+
by the given distance. ``turtle.left(...)`` takes a number of degrees which you
54
+
want to rotate to the left. There is also ``turtle.backward(...)`` and
55
+
``turtle.right(...)``, too.
56
+
57
+
.. note::
58
+
Want to start fresh? You can type ``turtle.reset()`` to clear the drawing
59
+
that your ``turtle`` has made so far. We'll go into more detail on
60
+
``turtle.reset()`` in just a bit.
48
61
49
62
The standard turtle is just a triangle. That's no fun! Let's make it a turtle
50
63
instead with the ``turtle.shape()`` command::
@@ -70,10 +83,10 @@ until you click on it::
70
83
71
84
.. note::
72
85
73
-
Python is a programming language where horizontal indenting of text is
74
-
important. We'll learn all about this in the Functions chapter later on,
75
-
but for now just keep in mind that stray spaces or tabs before any line
76
-
of Python code will cause an unexpected error.
86
+
Python is a programming language where horizontal indenting of text is
87
+
important. We'll learn all about this in the Functions chapter later on,
88
+
but for now just keep in mind that stray spaces or tabs before any line
89
+
of Python code can cause an unexpected error.
77
90
78
91
Drawing a square
79
92
================
@@ -97,6 +110,8 @@ Draw a square as in the following picture:
97
110
98
111
For a square you will probably need a right angle, which is 90 degrees.
99
112
113
+
.. rst-class:: solution
114
+
100
115
Solution
101
116
--------
102
117
@@ -136,7 +151,9 @@ key to exit the pager.
136
151
137
152
NameError: name 'turtle' is not defined
138
153
139
-
when trying to view help? In Python you have to import names before you can refer to them, so in a new Python interactive shell you'll need to ``import turtle`` before ``help(turtle.color)`` will work.
154
+
when trying to view help? In Python you have to import names before you
155
+
can refer to them, so in a new Python interactive shell you'll need to
156
+
``import turtle`` before ``help(turtle.color)`` will work.
140
157
141
158
Another way to find out about functions is to browse the `online documentation`_.
142
159
@@ -168,6 +185,8 @@ Can you draw a rectangle too?
168
185
169
186
.. image:: /images/rectangle.png
170
187
188
+
.. rst-class:: solution
189
+
171
190
Solution
172
191
--------
173
192
@@ -202,6 +221,8 @@ experiment with the angles between the individual squares.
202
221
203
222
The picture shows three 20 degree turns. You could try 20, 30 and 40, for example.
0 commit comments