-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject-6.qmd
365 lines (321 loc) · 35.2 KB
/
project-6.qmd
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
---
title: "Programming Project 6"
---
```{r}
#| echo: false
#| message: false
#| warning: false
library(tidyverse)
library(readxl)
assignments <- read_excel("assessment_schedule.xlsx") %>%
mutate(formatted_date = format(due_date, "%A, %B %d, %Y"))
```
Programming Projects are to be submitted to [gradescope](https://www.gradescope.com/courses/934148).
**Due date: `r assignments %>% filter(assessment == "Programming Project 6") %>% pull(formatted_date)` at 9pm**
For this programming project, you will create and manipulate 2D lists -- which are lists that contain lists.
# Cross stitch pattern creator
This assignment exercises the use of the random module, 2D lists, and for loops. You are going to write a Python script called `cross_stitch.py`.
Cross stitch designs are usually depicted on a grid, with each square on the grid corresponding to a stitch.
For the grid, x refers to the row number (starting at zero) and y refers to the column number (starting at zero).
You can learn more about [how to read a cross stitch pattern](https://stitchedmodern.com/blogs/news/how-to-read-a-cross-stitch-pattern). For this assignment, you will be creating different functions to create a random background and to add different shapes to the pattern.
This assignment has [starter code](starter-code/cross_stitch.py), which contains a global constant for a list of symbols to be used and a function to print the pattern called `print_pattern(pattern)`. The started code also imports the library random. Do not make changes to the starter code (changes might cause gradescope test fails).
## Create the random background
The first function you should write is the `create_background` function, which takes a width (how wide the pattern will be in number of stitches), a length (how many rows the pattern has), and number of unique symbols. Note how the last argument, `2`, makes it so the pattern is created with the first two symbols in the `SYMBOLS` list provided in the starter code.
Make sure you have `random.seed(123)` in this function so that every time we generate the same random number.
```{python}
#| echo: true
#| eval: false
pattern = create_background(20, 10, 2)
print_pattern(pattern)
```
<pre>
┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
│ ◎ │ △ │ ◎ │ △ │ △ │ ◎ │ ◎ │ △ │ △ │ △ │ ◎ │ ◎ │ ◎ │ △ │ △ │ ◎ │ ◎ │ ◎ │ △ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ △ │ ◎ │ ◎ │ △ │ △ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ △ │ △ │ △ │ △ │ △ │ ◎ │ △ │ △ │ △ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ △ │ ◎ │ △ │ △ │ △ │ △ │ △ │ ◎ │ ◎ │ ◎ │ △ │ △ │ ◎ │ △ │ △ │ △ │ ◎ │ △ │ △ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ △ │ ◎ │ ◎ │ ◎ │ △ │ ◎ │ △ │ ◎ │ △ │ ◎ │ △ │ △ │ ◎ │ △ │ ◎ │ ◎ │ △ │ △ │ △ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ △ │ ◎ │ ◎ │ △ │ △ │ △ │ △ │ △ │ ◎ │ ◎ │ ◎ │ △ │ ◎ │ ◎ │ △ │ ◎ │ △ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ △ │ ◎ │ △ │ △ │ △ │ ◎ │ △ │ △ │ △ │ ◎ │ ◎ │ △ │ ◎ │ ◎ │ △ │ ◎ │ ◎ │ ◎ │ △ │ △ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ △ │ △ │ △ │ ◎ │ △ │ ◎ │ ◎ │ △ │ △ │ ◎ │ ◎ │ △ │ ◎ │ △ │ △ │ △ │ △ │ △ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ △ │ ◎ │ △ │ ◎ │ △ │ ◎ │ △ │ ◎ │ △ │ ◎ │ ◎ │ △ │ △ │ △ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ △ │ ◎ │ ◎ │ △ │ ◎ │ △ │ ◎ │ ◎ │ △ │ △ │ △ │ ◎ │ △ │ △ │ △ │ △ │ ◎ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ △ │ △ │ ◎ │ ◎ │ △ │ △ │ △ │ △ │ △ │ △ │ ◎ │ △ │ △ │ ◎ │ ◎ │ △ │ ◎ │ △ │ △ │ △ │
└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘
</pre>
## Add a vertical stripe to the pattern
Write the function `add_v_stripe` that modifies and returns the pattern, by adding a stripe of certain width, using a specific symbol. The stripe should start at the first row of symbols (y = 0) and end at the last row of symbols.
```{python}
#| echo: true
#| eval: false
pattern = create_background(20, 10, 2)
# add vertical stripe at y = 2, of width = 4,
# using the symbol at index 3 in the list of symbols
pattern = add_v_stripe(pattern, 2, 4, 3)
print_pattern(pattern)
```
<pre>
┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
│ ◎ │ △ │ ● │ ● │ ● │ ● │ ◎ │ △ │ △ │ △ │ ◎ │ ◎ │ ◎ │ △ │ △ │ ◎ │ ◎ │ ◎ │ △ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ △ │ ◎ │ ● │ ● │ ● │ ● │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ △ │ △ │ △ │ △ │ △ │ ◎ │ △ │ △ │ △ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ △ │ ● │ ● │ ● │ ● │ △ │ △ │ ◎ │ ◎ │ ◎ │ △ │ △ │ ◎ │ △ │ △ │ △ │ ◎ │ △ │ △ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ △ │ ◎ │ ● │ ● │ ● │ ● │ △ │ ◎ │ △ │ ◎ │ △ │ △ │ ◎ │ △ │ ◎ │ ◎ │ △ │ △ │ △ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ● │ ● │ ● │ ● │ △ │ △ │ △ │ △ │ ◎ │ ◎ │ ◎ │ △ │ ◎ │ ◎ │ △ │ ◎ │ △ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ △ │ ◎ │ ● │ ● │ ● │ ● │ △ │ △ │ △ │ ◎ │ ◎ │ △ │ ◎ │ ◎ │ △ │ ◎ │ ◎ │ ◎ │ △ │ △ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ △ │ ● │ ● │ ● │ ● │ ◎ │ ◎ │ △ │ △ │ ◎ │ ◎ │ △ │ ◎ │ △ │ △ │ △ │ △ │ △ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ △ │ ● │ ● │ ● │ ● │ ◎ │ △ │ ◎ │ △ │ ◎ │ ◎ │ △ │ △ │ △ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ △ │ ● │ ● │ ● │ ● │ △ │ ◎ │ ◎ │ △ │ △ │ △ │ ◎ │ △ │ △ │ △ │ △ │ ◎ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ △ │ △ │ ● │ ● │ ● │ ● │ △ │ △ │ △ │ △ │ ◎ │ △ │ △ │ ◎ │ ◎ │ △ │ ◎ │ △ │ △ │ △ │
└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘
</pre>
## Add a horizontal stripe to the pattern
Write the function `add_h_stripe` that modifies and returns the pattern, by adding a stripe of certain height, using a specific symbol. The stripe should start at the first column of symbols (x = 0) and end at the last column of symbols.
```{python}
#| echo: true
#| eval: false
pattern = create_background(20, 10, 2)
# add vertical stripe at x = 2, of height = 5,
# using the symbol at index 6 in the list of symbols
pattern = add_h_stripe(pattern, 2, 5, 6)
print_pattern(pattern)
```
<pre>
┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
│ ◎ │ △ │ ◎ │ △ │ △ │ ◎ │ ◎ │ △ │ △ │ △ │ ◎ │ ◎ │ ◎ │ △ │ △ │ ◎ │ ◎ │ ◎ │ △ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ △ │ ◎ │ ◎ │ △ │ △ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ △ │ △ │ △ │ △ │ △ │ ◎ │ △ │ △ │ △ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │ ▲ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ △ │ ◎ │ △ │ ◎ │ △ │ ◎ │ △ │ ◎ │ △ │ ◎ │ ◎ │ △ │ △ │ △ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ △ │ ◎ │ ◎ │ △ │ ◎ │ △ │ ◎ │ ◎ │ △ │ △ │ △ │ ◎ │ △ │ △ │ △ │ △ │ ◎ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ △ │ △ │ ◎ │ ◎ │ △ │ △ │ △ │ △ │ △ │ △ │ ◎ │ △ │ △ │ ◎ │ ◎ │ △ │ ◎ │ △ │ △ │ △ │
└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘
</pre>
## Add a square to the pattern
Write the function `add_square` that modifies and returns the pattern, by adding a square of certain size, using a specific symbol.
```{python}
#| echo: true
#| eval: false
pattern = create_background(20, 10, 2)
# add a square to the pattern at coordinates x and y,
# of size 8 using symbol at index 14
pattern = add_square(pattern, 1, 5, 8, 14)
print_pattern(pattern)
```
<pre>
┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
│ ◎ │ △ │ ◎ │ △ │ △ │ ◎ │ ◎ │ △ │ △ │ △ │ ◎ │ ◎ │ ◎ │ △ │ △ │ ◎ │ ◎ │ ◎ │ △ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ △ │ ◎ │ ◎ │ △ │ △ │ ♦ │ ♦ │ ♦ │ ♦ │ ♦ │ ♦ │ ♦ │ ♦ │ △ │ △ │ △ │ ◎ │ △ │ △ │ △ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ △ │ ◎ │ △ │ △ │ ♦ │ ♦ │ ♦ │ ♦ │ ♦ │ ♦ │ ♦ │ ♦ │ ◎ │ △ │ △ │ △ │ ◎ │ △ │ △ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ △ │ ◎ │ ◎ │ ◎ │ △ │ ♦ │ ♦ │ ♦ │ ♦ │ ♦ │ ♦ │ ♦ │ ♦ │ △ │ ◎ │ ◎ │ △ │ △ │ △ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ △ │ ◎ │ ◎ │ ♦ │ ♦ │ ♦ │ ♦ │ ♦ │ ♦ │ ♦ │ ♦ │ △ │ ◎ │ ◎ │ △ │ ◎ │ △ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ △ │ ◎ │ △ │ △ │ △ │ ♦ │ ♦ │ ♦ │ ♦ │ ♦ │ ♦ │ ♦ │ ♦ │ ◎ │ △ │ ◎ │ ◎ │ ◎ │ △ │ △ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ △ │ △ │ △ │ ◎ │ ♦ │ ♦ │ ♦ │ ♦ │ ♦ │ ♦ │ ♦ │ ♦ │ ◎ │ △ │ △ │ △ │ △ │ △ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ △ │ ◎ │ △ │ ◎ │ ♦ │ ♦ │ ♦ │ ♦ │ ♦ │ ♦ │ ♦ │ ♦ │ △ │ △ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ △ │ ◎ │ ◎ │ △ │ ♦ │ ♦ │ ♦ │ ♦ │ ♦ │ ♦ │ ♦ │ ♦ │ △ │ △ │ △ │ △ │ ◎ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ △ │ △ │ ◎ │ ◎ │ △ │ △ │ △ │ △ │ △ │ △ │ ◎ │ △ │ △ │ ◎ │ ◎ │ △ │ ◎ │ △ │ △ │ △ │
└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘
</pre>
## Add a rectangle to the pattern
Write the function `add_rectangle` that modifies and returns the pattern, by adding a rectangle of certain width and height, using a specific symbol.
```{python}
#| echo: true
#| eval: false
pattern = create_background(20, 10, 2)
# add a rectangle to the pattern at coordinates x and y,
# of width 5 and height 3, using the symbol at index 4
add_rectangle(pattern, 2, 3, 5, 3, 4)
print_pattern(pattern)
```
<pre>
┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
│ ◎ │ △ │ ◎ │ △ │ △ │ ◎ │ ◎ │ △ │ △ │ △ │ ◎ │ ◎ │ ◎ │ △ │ △ │ ◎ │ ◎ │ ◎ │ △ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ △ │ ◎ │ ◎ │ △ │ △ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ △ │ △ │ △ │ △ │ △ │ ◎ │ △ │ △ │ △ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ △ │ ◎ │ ▣ │ ▣ │ ▣ │ ▣ │ ▣ │ ◎ │ ◎ │ ◎ │ △ │ △ │ ◎ │ △ │ △ │ △ │ ◎ │ △ │ △ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ △ │ ◎ │ ◎ │ ▣ │ ▣ │ ▣ │ ▣ │ ▣ │ △ │ ◎ │ △ │ △ │ ◎ │ △ │ ◎ │ ◎ │ △ │ △ │ △ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ △ │ ▣ │ ▣ │ ▣ │ ▣ │ ▣ │ △ │ △ │ ◎ │ ◎ │ ◎ │ △ │ ◎ │ ◎ │ △ │ ◎ │ △ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ △ │ ◎ │ △ │ △ │ △ │ ◎ │ △ │ △ │ △ │ ◎ │ ◎ │ △ │ ◎ │ ◎ │ △ │ ◎ │ ◎ │ ◎ │ △ │ △ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ △ │ △ │ △ │ ◎ │ △ │ ◎ │ ◎ │ △ │ △ │ ◎ │ ◎ │ △ │ ◎ │ △ │ △ │ △ │ △ │ △ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ △ │ ◎ │ △ │ ◎ │ △ │ ◎ │ △ │ ◎ │ △ │ ◎ │ ◎ │ △ │ △ │ △ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ △ │ ◎ │ ◎ │ △ │ ◎ │ △ │ ◎ │ ◎ │ △ │ △ │ △ │ ◎ │ △ │ △ │ △ │ △ │ ◎ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ △ │ △ │ ◎ │ ◎ │ △ │ △ │ △ │ △ │ △ │ △ │ ◎ │ △ │ △ │ ◎ │ ◎ │ △ │ ◎ │ △ │ △ │ △ │
└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘
</pre>
## Add four different triangles to the pattern
You should write four different functions to add four types of triangles to the pattern.
Each triangle function modifies and returns the pattern, by adding a triangle of certain size, using a specific symbol. Each triangle is half of a square -- each of the four options slices the square diagonally is four different ways.
```{python}
#| echo: true
#| eval: false
pattern = create_background(10, 10, 1)
# add a triangle to the pattern at coordinates x and y,
# of size 6, using the symbol at index 17
# the first 2 is x, the second 2 is y
add_triangle_a(pattern, 2, 2, 6, 17)
print_pattern(pattern)
```
<pre>
┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
│ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◘ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◘ │ ◘ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◘ │ ◘ │ ◘ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◘ │ ◘ │ ◘ │ ◘ │ ◎ │ ◎ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◘ │ ◘ │ ◘ │ ◘ │ ◘ │ ◎ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◘ │ ◘ │ ◘ │ ◘ │ ◘ │ ◘ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │
└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘
</pre>
```{python}
#| echo: true
#| eval: false
pattern = create_background(10, 10, 1)
# add a triangle to the pattern at coordinates x and y,
# of size 6, using the symbol at index 17
add_triangle_b(pattern, 2, 2, 6, 17)
print_pattern(pattern)
```
<pre>
┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
│ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◘ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◘ │ ◘ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◘ │ ◘ │ ◘ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◎ │ ◎ │ ◘ │ ◘ │ ◘ │ ◘ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◎ │ ◘ │ ◘ │ ◘ │ ◘ │ ◘ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◘ │ ◘ │ ◘ │ ◘ │ ◘ │ ◘ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │
└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘
</pre>
```{python}
#| echo: true
#| eval: false
pattern = create_background(10, 10, 1)
# add a triangle to the pattern at coordinates x and y,
# of size 6, using the symbol at index 17
add_triangle_c(pattern, 2, 2, 6, 17)
print_pattern(pattern)
```
<pre>
┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
│ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◘ │ ◘ │ ◘ │ ◘ │ ◘ │ ◘ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◘ │ ◘ │ ◘ │ ◘ │ ◘ │ ◎ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◘ │ ◘ │ ◘ │ ◘ │ ◎ │ ◎ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◘ │ ◘ │ ◘ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◘ │ ◘ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◘ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │
└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘
</pre>
```{python}
#| echo: true
#| eval: false
pattern = create_background(10, 10, 1)
# add a triangle to the pattern at coordinates x and y,
# of size 6, using the symbol at index 17
add_triangle_d(pattern, 2, 2, 6, 17)
print_pattern(pattern)
```
<pre>
┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
│ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◘ │ ◘ │ ◘ │ ◘ │ ◘ │ ◘ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◎ │ ◘ │ ◘ │ ◘ │ ◘ │ ◘ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◎ │ ◎ │ ◘ │ ◘ │ ◘ │ ◘ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◘ │ ◘ │ ◘ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◘ │ ◘ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◘ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │ ◎ │
└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘
</pre>