Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
ThinkPython/code/letters.py at master · xalgorithm/ThinkPython · GitHub
Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Small and medium teams
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
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
{{ message }}
xalgorithm
ThinkPython
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
ThinkPython
/
code
/
letters.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
278 lines (220 loc) · 5.05 KB
master
Breadcrumbs
ThinkPython
/
code
/
letters.py
Copy path
Top
File metadata and controls
Code
Blame
278 lines (220 loc) · 5.05 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
"""This module contains code from
Think Python by Allen B. Downey
http://thinkpython.com
Copyright 2012 Allen B. Downey
License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html
"""
from
swampy
.
TurtleWorld
import
*
from
polygon
import
circle
,
arc
# LEVEL 0 PRIMITIVES are provided by World.py.
# They include fd, bk, lt, rt, pu and pd
# LEVEL 1 PRIMITIVES are simple combinations of Level 0 primitives.
# They have no pre- or post-conditions.
def
fdlt
(
t
,
n
,
angle
=
90
):
"""forward and left"""
fd
(
t
,
n
)
lt
(
t
,
angle
)
def
fdbk
(
t
,
n
):
"""forward and back, ending at the original position"""
fd
(
t
,
n
)
bk
(
t
,
n
)
def
skip
(
t
,
n
):
"""lift the pen and move"""
pu
(
t
)
fd
(
t
,
n
)
pd
(
t
)
def
stump
(
t
,
n
,
angle
=
90
):
"""make a vertical line and leave the turtle at the top, facing right"""
lt
(
t
)
fd
(
t
,
n
)
rt
(
t
,
angle
)
def
hollow
(
t
,
n
):
"""move the turtle vertically and leave it at the top, facing right"""
lt
(
t
)
skip
(
t
,
n
)
rt
(
t
)
# LEVEL 2 PRIMITIVES use primitives from Levels 0 and 1
# to draw posts (vertical elements) and beams (horizontal elements)
# Level 2 primitives ALWAYS return the turtle to the original
# location and direction.
def
post
(
t
,
n
):
"""make a vertical line and return to the original position"""
lt
(
t
)
fdbk
(
t
,
n
)
rt
(
t
)
def
beam
(
t
,
n
,
height
):
"""make a horizontal line at the given height and return."""
hollow
(
t
,
n
*
height
)
fdbk
(
t
,
n
)
hollow
(
t
,
-
n
*
height
)
def
hangman
(
t
,
n
,
height
):
"""make a vertical line to the given height and a horizontal line
at the given height and then return.
This is efficient to implement, and turns out to be useful, but
it's not so semantically clean."""
stump
(
t
,
n
*
height
)
fdbk
(
t
,
n
)
lt
(
t
)
bk
(
t
,
n
*
height
)
rt
(
t
)
def
diagonal
(
t
,
x
,
y
):
"""make a diagonal line to the given x, y offsets and return"""
from
math
import
atan2
,
sqrt
,
pi
angle
=
atan2
(
y
,
x
)
*
180
/
pi
dist
=
sqrt
(
x
**
2
+
y
**
2
)
lt
(
t
,
angle
)
fdbk
(
t
,
dist
)
rt
(
t
,
angle
)
def
vshape
(
t
,
n
,
height
):
diagonal
(
t
,
-
n
/
2
,
height
*
n
)
diagonal
(
t
,
n
/
2
,
height
*
n
)
def
bump
(
t
,
n
,
height
):
"""make a bump with radius n at height*n
"""
stump
(
t
,
n
*
height
)
arc
(
t
,
n
/
2.0
,
180
)
lt
(
t
)
fdlt
(
t
,
n
*
height
+
n
)
"""
The letter-drawing functions all have the precondition
that the turtle is in the lower-left corner of the letter,
and postcondition that the turtle is in the lower-right
corner, facing in the direction it started in.
They all take a turtle as the first argument and a size (n)
as the second. Most letters are (n) units wide and (2n) units
high.
"""
def
draw_a
(
t
,
n
):
diagonal
(
t
,
n
/
2
,
2
*
n
)
beam
(
t
,
n
,
1
)
skip
(
t
,
n
)
diagonal
(
t
,
-
n
/
2
,
2
*
n
)
def
draw_b
(
t
,
n
):
bump
(
t
,
n
,
1
)
bump
(
t
,
n
,
0
)
skip
(
t
,
n
/
2
)
def
draw_c
(
t
,
n
):
hangman
(
t
,
n
,
2
)
fd
(
t
,
n
)
def
draw_d
(
t
,
n
):
bump
(
t
,
2
*
n
,
0
)
skip
(
t
,
n
)
def
draw_ef
(
t
,
n
):
hangman
(
t
,
n
,
2
)
hangman
(
t
,
n
,
1
)
def
draw_e
(
t
,
n
):
draw_ef
(
t
,
n
)
fd
(
t
,
n
)
def
draw_f
(
t
,
n
):
draw_ef
(
t
,
n
)
skip
(
t
,
n
)
def
draw_g
(
t
,
n
):
hangman
(
t
,
n
,
2
)
fd
(
t
,
n
/
2
)
beam
(
t
,
n
/
2
,
2
)
fd
(
t
,
n
/
2
)
post
(
t
,
n
)
def
draw_h
(
t
,
n
):
post
(
t
,
2
*
n
)
hangman
(
t
,
n
,
1
)
skip
(
t
,
n
)
post
(
t
,
2
*
n
)
def
draw_i
(
t
,
n
):
beam
(
t
,
n
,
2
)
fd
(
t
,
n
/
2
)
post
(
t
,
2
*
n
)
fd
(
t
,
n
/
2
)
def
draw_j
(
t
,
n
):
beam
(
t
,
n
,
2
)
arc
(
t
,
n
/
2
,
90
)
fd
(
t
,
3
*
n
/
2
)
skip
(
t
,
-
2
*
n
)
rt
(
t
)
skip
(
t
,
n
/
2
)
def
draw_k
(
t
,
n
):
post
(
t
,
2
*
n
)
stump
(
t
,
n
,
180
)
vshape
(
t
,
2
*
n
,
0.5
)
fdlt
(
t
,
n
)
skip
(
t
,
n
)
def
draw_l
(
t
,
n
):
post
(
t
,
2
*
n
)
fd
(
t
,
n
)
def
draw_n
(
t
,
n
):
post
(
t
,
2
*
n
)
skip
(
t
,
n
)
diagonal
(
t
,
-
n
,
2
*
n
)
post
(
t
,
2
*
n
)
def
draw_m
(
t
,
n
):
post
(
t
,
2
*
n
)
draw_v
(
t
,
n
)
post
(
t
,
2
*
n
)
def
draw_o
(
t
,
n
):
skip
(
t
,
n
)
circle
(
t
,
n
)
skip
(
t
,
n
)
def
draw_p
(
t
,
n
):
bump
(
t
,
n
,
1
)
skip
(
t
,
n
/
2
)
def
draw_q
(
t
,
n
):
draw_o
(
t
,
n
)
diagonal
(
t
,
-
n
/
2
,
n
)
def
draw_r
(
t
,
n
):
draw_p
(
t
,
n
)
diagonal
(
t
,
-
n
/
2
,
n
)
def
draw_s
(
t
,
n
):
fd
(
t
,
n
/
2
)
arc
(
t
,
n
/
2
,
180
)
arc
(
t
,
n
/
2
,
-
180
)
fdlt
(
t
,
n
/
2
,
-
90
)
skip
(
t
,
2
*
n
)
lt
(
t
)
def
draw_t
(
t
,
n
):
beam
(
t
,
n
,
2
)
skip
(
t
,
n
/
2
)
post
(
t
,
2
*
n
)
skip
(
t
,
n
/
2
)
def
draw_u
(
t
,
n
):
post
(
t
,
2
*
n
)
fd
(
t
,
n
)
post
(
t
,
2
*
n
)
def
draw_v
(
t
,
n
):
skip
(
t
,
n
/
2
)
vshape
(
t
,
n
,
2
)
skip
(
t
,
n
/
2
)
def
draw_w
(
t
,
n
):
draw_v
(
t
,
n
)
draw_v
(
t
,
n
)
def
draw_x
(
t
,
n
):
diagonal
(
t
,
n
,
2
*
n
)
skip
(
t
,
n
)
diagonal
(
t
,
-
n
,
2
*
n
)
def
draw_v
(
t
,
n
):
skip
(
t
,
n
/
2
)
diagonal
(
t
,
-
n
/
2
,
2
*
n
)
diagonal
(
t
,
n
/
2
,
2
*
n
)
skip
(
t
,
n
/
2
)
def
draw_y
(
t
,
n
):
skip
(
t
,
n
/
2
)
stump
(
t
,
n
)
vshape
(
t
,
n
,
1
)
rt
(
t
)
fdlt
(
t
,
n
)
skip
(
t
,
n
/
2
)
def
draw_z
(
t
,
n
):
beam
(
t
,
n
,
2
)
diagonal
(
t
,
n
,
2
*
n
)
fd
(
t
,
n
)
def
draw_
(
t
,
n
):
# draw a space
skip
(
t
,
n
)
if
__name__
==
'__main__'
:
world
=
TurtleWorld
()
# create and position the turtle
size
=
20
bob
=
Turtle
()
bob
.
delay
=
0.01
for
f
in
[
draw_h
,
draw_e
,
draw_l
,
draw_l
,
draw_o
]:
f
(
bob
,
size
)
skip
(
bob
,
size
)
wait_for_user
()
You can’t perform that action at this time.