-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path02.html
More file actions
1412 lines (1297 loc) · 113 KB
/
02.html
File metadata and controls
1412 lines (1297 loc) · 113 KB
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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Shape Properties with Variables — Geometry Playground</title>
<!-- SEO -->
<meta name="description" content="Chapter II of Geometry Playground: shape properties through Swift variables. Draw irregular polygons, explore lines of symmetry, and use variables to drive geometry on iPad or Mac." />
<meta name="keywords" content="Swift Playgrounds, shape properties, variables, irregular polygons, symmetry, area, Swift programming, geometry chapter 2, iPad coding, IM1" />
<meta name="author" content="Daniel Budd" />
<meta name="robots" content="index, follow" />
<link rel="canonical" href="https://dbbudd.github.io/02.html" />
<!-- Open Graph -->
<meta property="og:type" content="article" />
<meta property="og:site_name" content="Geometry Playground" />
<meta property="og:title" content="Shape Properties with Variables — Geometry Playground" />
<meta property="og:description" content="Chapter II: shape properties through Swift variables. Draw irregular polygons, explore lines of symmetry, and use variables to drive geometry on iPad or Mac." />
<meta property="og:url" content="https://dbbudd.github.io/02.html" />
<meta property="og:image" content="https://dbbudd.github.io/images/og-card.png" />
<!-- Twitter Card -->
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:creator" content="@DanielBBudd" />
<meta name="twitter:title" content="Shape Properties with Variables — Geometry Playground" />
<meta name="twitter:description" content="Chapter II: shape properties through Swift variables. Draw irregular polygons, explore lines of symmetry, and use variables to drive geometry on iPad or Mac." />
<meta name="twitter:image" content="https://dbbudd.github.io/images/og-card.png" />
<!-- Structured data -->
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "LearningResource",
"name": "Shape Properties with Variables — Geometry Playground Chapter II",
"description": "Shape properties through Swift variables. Draw irregular polygons, explore lines of symmetry, and use variables to drive geometry with Swift Playgrounds on iPad or Mac.",
"url": "https://dbbudd.github.io/02.html",
"isPartOf": { "@type": "Course", "name": "Geometry Playground", "url": "https://dbbudd.github.io/" },
"author": { "@type": "Person", "name": "Daniel Budd" },
"inLanguage": "en",
"educationalLevel": "High School",
"learningResourceType": "Interactive Tutorial",
"isAccessibleForFree": true,
"teaches": "Shape Properties, Variables, Irregular Polygons, Reflective Symmetry, Area of Polygons, Coordinate Offsets"
}
</script>
<link rel="stylesheet" href="course-ui/course-ui.css?v=4" />
<link rel="stylesheet" href="styles.css?v=5" />
<script>
window.CourseUI = {
brand: { name: 'Geometry Playground', accent: '#F2B13E' },
reading: { readingLine: true, readingPos: true, focusMode: true },
search: {
enabled: true,
scope: 'site',
pages: [
'index.html',
'01.html', '02.html', '03.html',
'04.html', '05.html', '06.html'
]
},
vocab: {
enabled: true,
autoWrap: true,
contentSelector: '.section-hero .lead, .article p, .article li'
},
mobile: {
drawer: {
sections: [
{ title: 'Chapters', clone: '#chapterPill .nav-dropdown' },
{ title: 'Sections', clone: '.sidebar nav' }
]
}
}
};
</script>
<script src="vocab/geometry.js?v=4"></script>
<script src="course-ui/course-ui.js?v=4" defer></script>
</head>
<body>
<a class="cu-skip-link" href="#chapter-top">Skip to main content</a>
<!-- ══════════════════════════════════════════════════════════
TOP BAR
══════════════════════════════════════════════════════════ -->
<header class="topbar" id="topbar">
<a href="index.html" class="topbar-logo">
<span>◆</span>Geometry Playground
</a>
<div class="topbar-divider"></div>
<!-- Chapter picker -->
<div class="nav-pill" id="chapterPill">
<button class="nav-pill-btn" onclick="togglePill('chapterPill')">
<span class="pill-label">Chapter</span>
II
<svg width="10" height="6" viewBox="0 0 10 6" fill="none"><path d="M1 1l4 4 4-4" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg>
</button>
<div class="nav-dropdown">
<div class="nav-dropdown-heading">Chapters</div>
<a href="01.html"><span class="dd-num">I</span> Coordinate Geometry</a>
<a href="02.html" class="current"><span class="dd-num">II</span> Shape Properties</a>
<a href="03.html"><span class="dd-num">III</span> Polygon Patterns</a>
<a href="04.html"><span class="dd-num">IV</span> Sorting Shapes</a>
<a href="05.html"><span class="dd-num">V</span> Similarity</a>
<a href="06.html"><span class="dd-num">VI</span> Composite Figures</a>
</div>
</div>
<!-- Section picker -->
<div class="nav-pill" id="sectionPill">
<button class="nav-pill-btn" onclick="togglePill('sectionPill')">
<span class="pill-label">Section</span>
<span id="activeSectionLabel">Adding Pens</span>
<svg width="10" height="6" viewBox="0 0 10 6" fill="none"><path d="M1 1l4 4 4-4" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg>
</button>
<div class="nav-dropdown" id="sectionDropdown">
<div class="nav-dropdown-heading">Sections — Chapter II</div>
<a href="#adding-pens" onclick="closePills()"><span class="dd-num">01</span> Adding Pens</a>
<a href="#multiple-pens" onclick="closePills()"><span class="dd-num">02</span> Multiple Pens</a>
<a href="#turning-both-ways" onclick="closePills()"><span class="dd-num">03</span> Turning Both Ways</a>
<a href="#two-squares" onclick="closePills()"><span class="dd-num">04</span> Two Squares</a>
<a href="#thicker-lines" onclick="closePills()"><span class="dd-num">05</span> Thicker Lines</a>
<a href="#coloured-triangle" onclick="closePills()"><span class="dd-num">06</span> Coloured Triangle</a>
<a href="#diamond" onclick="closePills()"><span class="dd-num">07</span> Diamond</a>
<a href="#fill-it-in" onclick="closePills()"><span class="dd-num">08</span> Fill It In</a>
<a href="#coloured-squares" onclick="closePills()"><span class="dd-num">09</span> Coloured Squares</a>
<a href="#variables" onclick="closePills()"><span class="dd-num">10</span> Variables</a>
<div class="nav-dropdown-sep"></div>
<a href="#house" onclick="closePills()"><span class="dd-num">11</span> House</a>
<a href="#calculate" onclick="closePills()"><span class="dd-num">12</span> Calculate</a>
<a href="#variable-house" onclick="closePills()"><span class="dd-num">13</span> Variable House</a>
<a href="#red-cross" onclick="closePills()"><span class="dd-num">14</span> Red Cross</a>
<a href="#simple-snowflake" onclick="closePills()"><span class="dd-num">15</span> Simple Snowflake</a>
<a href="#parallel-lines" onclick="closePills()"><span class="dd-num">16</span> Parallel Lines</a>
<a href="#letter-z" onclick="closePills()"><span class="dd-num">17</span> Letter Z</a>
<a href="#rhombus" onclick="closePills()"><span class="dd-num">18</span> Rhombus</a>
<a href="#parallelogram" onclick="closePills()"><span class="dd-num">19</span> Parallelogram</a>
<a href="#polygon-explorer" onclick="closePills()"><span class="dd-num">20</span> Polygon Explorer</a>
<a href="#angle-classification" onclick="closePills()"><span class="dd-num">21</span> Angle Classification</a>
</div>
</div>
<!-- Progress -->
<div class="topbar-progress">
<span class="progress-text" id="progressText">0 / 18 done</span>
<div class="progress-bar-wrap">
<div class="progress-bar-fill" id="progressBarFill"></div>
</div>
</div>
</header>
<!-- ══════════════════════════════════════════════════════════
LAYOUT
══════════════════════════════════════════════════════════ -->
<div class="layout">
<!-- ── SIDEBAR ─────────────────────────────────────────── -->
<aside class="sidebar">
<div class="sidebar-chapter">Chapter II</div>
<nav id="sidebarNav">
<a href="#adding-pens" data-section="adding-pens"><span class="nav-num">01</span><span>Adding Pens<br><span class="nav-badge badge-tutorial">Tutorial</span></span><span class="nav-done">✓</span></a>
<a href="#multiple-pens" data-section="multiple-pens"><span class="nav-num">02</span><span>Multiple Pens<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#turning-both-ways" data-section="turning-both-ways"><span class="nav-num">03</span><span>Turning Both Ways<br><span class="nav-badge badge-tutorial">Tutorial</span></span><span class="nav-done">✓</span></a>
<a href="#two-squares" data-section="two-squares"><span class="nav-num">04</span><span>Two Squares<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#thicker-lines" data-section="thicker-lines"><span class="nav-num">05</span><span>Thicker Lines<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#coloured-triangle" data-section="coloured-triangle"><span class="nav-num">06</span><span>Coloured Triangle<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#diamond" data-section="diamond"><span class="nav-num">07</span><span>Diamond<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#fill-it-in" data-section="fill-it-in"><span class="nav-num">08</span><span>Fill It In<br><span class="nav-badge badge-tutorial">Tutorial</span></span><span class="nav-done">✓</span></a>
<a href="#coloured-squares" data-section="coloured-squares"><span class="nav-num">09</span><span>Coloured Squares<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#variables" data-section="variables"><span class="nav-num">10</span><span>Variables<br><span class="nav-badge badge-tutorial">Tutorial</span></span><span class="nav-done">✓</span></a>
<a href="#house" data-section="house"><span class="nav-num">11</span><span>House<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#calculate" data-section="calculate"><span class="nav-num">12</span><span>Calculate<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#variable-house" data-section="variable-house"><span class="nav-num">13</span><span>Variable House<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#red-cross" data-section="red-cross"><span class="nav-num">14</span><span>Red Cross<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#simple-snowflake" data-section="simple-snowflake"><span class="nav-num">15</span><span>Simple Snowflake<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#parallel-lines" data-section="parallel-lines"><span class="nav-num">16</span><span>Parallel Lines<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#letter-z" data-section="letter-z"><span class="nav-num">17</span><span>Letter Z<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#rhombus" data-section="rhombus"><span class="nav-num">18</span><span>Rhombus<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#parallelogram" data-section="parallelogram"><span class="nav-num">19</span><span>Parallelogram<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#polygon-explorer" data-section="polygon-explorer"><span class="nav-num">20</span><span>Polygon Explorer<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#angle-classification" data-section="angle-classification"><span class="nav-num">21</span><span>Angle Classification<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
</nav>
</aside>
<!-- ── MAIN CONTENT ─────────────────────────────────────── -->
<main class="content">
<!-- Chapter Banner -->
<section class="section-hero chapter-banner" id="chapter-top">
<div class="ch-label">Chapter II of VI</div>
<h1>Shape Properties with Variables</h1>
<p class="lead">Store side lengths, colours, and coordinates in <code style="background:rgba(255,255,255,0.15);color:#F2B13E">var</code> and <code style="background:rgba(255,255,255,0.15);color:#F2B13E">let</code>, then reuse them to build diamonds, crosses, snowflakes, and rhombuses. Along the way you'll investigate symmetry, parallel sides, and other shape properties that define what makes a polygon a polygon.</p>
<div class="banner-meta">
<div class="banner-stat"><span class="stat-num">21</span><span class="stat-label">Sections</span></div>
<div class="banner-stat"><span class="stat-num">3</span><span class="stat-label">Tutorials</span></div>
<div class="banner-stat"><span class="stat-num">18</span><span class="stat-label">Exercises</span></div>
</div>
</section>
<!-- ═══════════════════ 01 — ADDING PENS ═══════════════════ -->
<section id="adding-pens">
<div class="section-hero">
<span class="section-tag tutorial">◆ Tutorial</span>
<h1>Adding Pens</h1>
<p class="lead">Discover how to use the <code>addShape(pen:)</code> call and what happens when you create multiple independent pens on the same canvas.</p>
<button class="complete-btn" data-id="adding-pens" onclick="toggleComplete(this)"><span class="btn-icon">○</span> Mark as Complete</button>
</div>
<div class="article">
<h2>Rendering Shapes</h2>
<p>In Chapter I you drew with a single pen. This chapter introduces the key idea of <strong>multiple independent pens</strong> — each one with its own colour, thickness, and position. To display a pen's path on the canvas you must call <code>addShape(pen:)</code> — think of it as "print this pen's drawing to the screen".</p>
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Swift</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="kw">var</span> <span class="vr">p1</span> = <span class="tp">Pen</span>()
<span class="vr">p1</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="fn">addShape</span>(pen: <span class="vr">p1</span>) <span class="cm">// render p1's path</span>
<span class="kw">var</span> <span class="vr">p2</span> = <span class="tp">Pen</span>()
<span class="vr">p2</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">p2</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="fn">addShape</span>(pen: <span class="vr">p2</span>) <span class="cm">// render p2's path</span></pre>
</div>
<blockquote><strong>Why <code>var p = Pen()</code> and not <code>let p = Pen()</code>?</strong> Because a pen <em>changes</em> as you call methods on it — moving, turning, setting colour. Swift uses <code>var</code> for things that can change and <code>let</code> for things that stay the same. A pen has to be <code>var</code>; a fixed side length like <code>let side = 100</code> should be <code>let</code>. You'll see this distinction again in the Variables tutorial (Section 10).</blockquote>
<blockquote><strong>Each pen is an independent draft.</strong> When you create <code>p2</code>, it starts fresh at the origin (0, 0) facing right — <em>not</em> where <code>p1</code> left off. Each pen tracks its own position and direction. This is what makes multiple pens powerful: you can draw unrelated shapes without them interfering with each other's state.</blockquote>
<blockquote><strong>Nothing appears until you call <code>addShape</code>.</strong> The pen records its path quietly in memory until you hand it to <code>addShape(pen:)</code>, which renders it onto the canvas. You can build up a complex path with many calls and then render it all at once, or render incrementally. Forgetting <code>addShape</code> is the single most common reason a student's code runs without errors but draws nothing!</blockquote>
<div class="img-wrap">
<img src="images/02-01-adding-pens.png" alt="Two Lines">
</div>
<div class="im-table-wrap">
<div class="im-table-header">Curriculum Connections</div>
<table>
<tr><th>Concept</th><th>Connection</th></tr>
<tr><td>Coordinate geometry</td><td>Each pen starts at the origin — independent paths share the same coordinate system</td></tr>
<tr><td>Line segments</td><td>Each <code>addLine</code> call produces a directed segment with defined start and end points</td></tr>
</table>
</div>
</div>
</section>
<!-- ═══════════════════ 02 — MULTIPLE PENS ═══════════════════ -->
<section id="multiple-pens">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>Multiple Pens</h1>
<p class="lead">Draw two separate squares side-by-side using two independent pens — one starting at the origin and the other offset to the right.</p>
<button class="complete-btn" data-id="multiple-pens" onclick="toggleComplete(this)"><span class="btn-icon">○</span> Mark as Complete</button>
</div>
<div class="article">
<h2>Your Task</h2>
<p>Create two pens. Draw a 100-unit square with <code>p1</code> starting at the origin. Then use <code>p2</code> — start it at (150, 0) using <code>move(distance:)</code> or by setting its position — and draw a second 100-unit square.</p>
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Swift</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="kw">var</span> <span class="vr">p1</span> = <span class="tp">Pen</span>()
<span class="cm">// Draw first square with p1</span>
<span class="kw">var</span> <span class="vr">p2</span> = <span class="tp">Pen</span>()
<span class="cm">// Position p2 and draw second square</span>
<span class="fn">addShape</span>(pen: <span class="vr">p1</span>)
<span class="fn">addShape</span>(pen: <span class="vr">p2</span>)</pre>
</div>
<div class="img-wrap">
<img src="images/02-02-multiple-pens.png" alt="Two Lines">
</div>
<button class="solution-toggle" onclick="toggleSolution(this,'sol-multiple-pens')">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
Show Solution
</button>
<blockquote><strong>Translation in geometry.</strong> Offsetting <code>p2</code> by 150 units to the right is a <strong>rigid translation</strong> — every point of <code>p2</code>'s square is shifted by the same vector (+150, 0) from <code>p1</code>'s square. The two squares are <em>congruent</em>: same shape, same size, just at different positions. Translation is one of three rigid motions (along with rotation and reflection) that preserve distances and angles. You'll meet all three throughout this chapter.</blockquote>
<blockquote><strong>Two pens, two origins.</strong> Both pens start at the canvas origin (0, 0) by default. Calling <code>p2.move(distance: 150)</code> slides <code>p2</code> forward by 150 units <em>without drawing</em> — so when you then call <code>addLine</code>, the line starts at (150, 0). Think of <code>move</code> as lifting the pen off the paper, sliding it, then putting it back down ready to draw.</blockquote>
<div class="solution-body" id="sol-multiple-pens">
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Swift</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="kw">var</span> <span class="vr">p1</span> = <span class="tp">Pen</span>()
<span class="vr">p1</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">p1</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">p1</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">p1</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">p1</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">p1</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">p1</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="fn">addShape</span>(pen: <span class="vr">p1</span>)
<span class="kw">var</span> <span class="vr">p2</span> = <span class="tp">Pen</span>()
<span class="vr">p2</span>.<span class="fn">move</span>(distance: <span class="num">150</span>) <span class="cm">// move right without drawing</span>
<span class="vr">p2</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">p2</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">p2</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">p2</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">p2</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">p2</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">p2</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="fn">addShape</span>(pen: <span class="vr">p2</span>)</pre>
</div>
</div>
<div class="im-table-wrap">
<div class="im-table-header">Curriculum Connections</div>
<table>
<tr><th>Concept</th><th>Connection</th></tr>
<tr><td>Translations</td><td>Offsetting <code>p2</code> by 150 units is a <strong>translation</strong> — a rigid motion that shifts every point the same distance</td></tr>
<tr><td>Congruence</td><td>Both squares are <strong>congruent</strong> — same shape, same size, different position</td></tr>
</table>
</div>
</div>
</section>
<!-- ═══════════════════ 03 — TURNING BOTH WAYS ═══════════════════ -->
<section id="turning-both-ways">
<div class="section-hero">
<span class="section-tag tutorial">◆ Tutorial</span>
<h1>Turning Both Ways</h1>
<p class="lead">Explore negative degree values — turning right (clockwise) instead of left — and understand how this unlocks a wider range of shapes.</p>
<button class="complete-btn" data-id="turning-both-ways" onclick="toggleComplete(this)"><span class="btn-icon">○</span> Mark as Complete</button>
</div>
<div class="article">
<h2>Positive vs Negative Turns</h2>
<p>A positive turn angle rotates the pen <strong>anti-clockwise</strong> (left). A negative angle rotates it <strong>clockwise</strong> (right). This matches the standard mathematical convention you'll see in trigonometry and coordinate geometry.</p>
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Swift</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>) <span class="cm">// rotate LEFT 90° (anti-clockwise)</span>
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: -<span class="num">90</span>) <span class="cm">// rotate RIGHT 90° (clockwise)</span></pre>
</div>
<blockquote><strong>Why "positive = anti-clockwise"?</strong> It feels backwards at first (clocks go clockwise, so shouldn't positive mean clockwise?). But mathematicians chose the opposite convention centuries ago, for a good reason: in standard <em>(x, y)</em> coordinate geometry, rotating the positive x-axis toward the positive y-axis goes <em>counter-clockwise</em>. Keeping that direction "positive" means angle formulas work cleanly without sign flips. Every maths textbook and programming language uses this convention — get comfortable with it now.</blockquote>
<blockquote><strong>If you walked around a shape.</strong> When you drew a square in Chapter I by turning 90° four times, you were walking counter-clockwise around the square — because positive turns go left (anti-clockwise). That's why the square "grew upward and to the right" from your starting corner. Try drawing one with <code>turn(degrees: -90)</code> instead, and you'll see the square grow downward and to the right: you're walking clockwise now, tracing the same shape in the mirror direction.</blockquote>
<div class="img-wrap">
<img src="images/02-03-turning-both-ways.png" alt="Two Lines">
</div>
<div class="im-table-wrap">
<div class="im-table-header">Curriculum Connections</div>
<table>
<tr><th>Concept</th><th>Connection</th></tr>
<tr><td>Directed angles</td><td>Positive = anti-clockwise, negative = clockwise — this is the convention used in trigonometry and coordinate geometry</td></tr>
<tr><td>Rotations</td><td>Turning the pen is equivalent to a <strong>rotation</strong> of the direction vector around the pen's current position</td></tr>
</table>
</div>
</div>
</section>
<!-- ═══════════════════ 04 — TWO SQUARES ═══════════════════ -->
<section id="two-squares">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>Two Squares</h1>
<p class="lead">Draw a large square (200 units) and a small square (100 units) that shares the same bottom-left corner — creating a nested effect.</p>
<button class="complete-btn" data-id="two-squares" onclick="toggleComplete(this)"><span class="btn-icon">○</span> Mark as Complete</button>
</div>
<div class="article">
<h2>Your Task</h2>
<p>Use a single pen to draw both squares without lifting it (use <code>move</code> to reposition if needed), or use two separate pens.</p>
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Swift</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="kw">var</span> <span class="vr">p</span> = <span class="tp">Pen</span>()
<span class="cm">// Draw large square (200 units)</span>
<span class="cm">// Draw small square (100 units)</span>
<span class="fn">addShape</span>(pen: <span class="vr">p</span>)</pre>
</div>
<div class="img-wrap">
<img src="images/02-04-two-squares.png" alt="Two squares">
</div>
<button class="solution-toggle" onclick="toggleSolution(this,'sol-two-squares')">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
Show Solution
</button>
<blockquote><strong>Similarity vs congruence.</strong> Two shapes are <strong>congruent</strong> if they have the same size and shape — one is a translated/rotated/reflected copy of the other. Two shapes are <strong>similar</strong> if they have the same shape but possibly different sizes — one is a scaled copy of the other. The two squares in this exercise are <em>similar</em> (same shape, different sizes) but not congruent (different sizes). The ratio of their side lengths, 200 : 100, is called the <strong>scale factor</strong>. The ratio of their areas is the scale factor squared: <code>(200/100)² = 4</code> — the large square has four times the area of the small one.</blockquote>
<blockquote><strong>Why the pen ends up back at the starting corner.</strong> After drawing each square, the pen's heading has rotated by <code>4 × 90° = 360°</code> — a full circle. Combined with 4 equal-length sides, the pen returns to exactly its starting position. This is why you can "draw another square" by continuing from the same pen without repositioning — it's already back home.</blockquote>
<div class="solution-body" id="sol-two-squares">
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Swift</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="kw">var</span> <span class="vr">p</span> = <span class="tp">Pen</span>()
<span class="cm">// Large square: 200 units</span>
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">200</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">200</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">200</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">200</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="cm">// Small square: 100 units (starts from the same corner)</span>
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="fn">addShape</span>(pen: <span class="vr">p</span>)</pre>
</div>
</div>
<div class="im-table-wrap">
<div class="im-table-header">Curriculum Connections</div>
<table>
<tr><th>Concept</th><th>Connection</th></tr>
<tr><td>Similarity</td><td>The two squares are <strong>similar</strong> — same shape but different sizes, with a scale factor of 2:1</td></tr>
<tr><td>Perimeter</td><td>Perimeter of large square = 4 × 200 = 800; small = 4 × 100 = 400</td></tr>
</table>
</div>
</div>
</section>
<!-- ═══════════════════ 05 — THICKER LINES ═══════════════════ -->
<section id="thicker-lines">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>Thicker Lines</h1>
<p class="lead">Use the <code>lineWidth</code> property to draw a bold triangle — and explore how stroke width affects a shape's visual weight.</p>
<button class="complete-btn" data-id="thicker-lines" onclick="toggleComplete(this)"><span class="btn-icon">○</span> Mark as Complete</button>
</div>
<div class="article">
<h2>Your Task</h2>
<p>Draw an equilateral triangle (3 sides, turning 120° at each corner) with a <code>lineWidth</code> of 6.</p>
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Swift</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="kw">var</span> <span class="vr">p</span> = <span class="tp">Pen</span>()
<span class="vr">p</span>.<span class="fn">lineWidth</span> = <span class="num">6</span>
<span class="cm">// Draw equilateral triangle</span>
<span class="fn">addShape</span>(pen: <span class="vr">p</span>)</pre>
</div>
<div class="img-wrap">
<img src="images/02-05-thicker-lines.png" alt="Thicker lines">
</div>
<button class="solution-toggle" onclick="toggleSolution(this,'sol-thicker-lines')">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
Show Solution
</button>
<blockquote><strong>Why 120° for a triangle?</strong> Same reason as Chapter I: if you walked around the triangle, your total turning would be 360° (a full rotation), split equally across 3 corners — <code>360° ÷ 3 = 120°</code> per turn. You'll see this "exterior angle = 360° ÷ n" formula again and again for every regular polygon.</blockquote>
<blockquote><strong>Line width vs shape width.</strong> <code>lineWidth</code> controls the <em>stroke thickness</em> — how fat the drawn line is — not the size of the shape. A triangle with side 150 and <code>lineWidth = 6</code> is the same size as one with <code>lineWidth = 1</code>, just drawn with a thicker pen. Think of it like choosing a marker vs a fine-tipped pen: same drawing, different visual weight.</blockquote>
<div class="solution-body" id="sol-thicker-lines">
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Swift</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="kw">var</span> <span class="vr">p</span> = <span class="tp">Pen</span>()
<span class="vr">p</span>.<span class="fn">lineWidth</span> = <span class="num">6</span>
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">150</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">120</span>)
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">150</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">120</span>)
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">150</span>)
<span class="fn">addShape</span>(pen: <span class="vr">p</span>)</pre>
</div>
</div>
<div class="im-table-wrap">
<div class="im-table-header">Curriculum Connections</div>
<table>
<tr><th>Concept</th><th>Connection</th></tr>
<tr><td>Equilateral triangle</td><td>All three sides equal; all interior angles = 60°; exterior turn = 120°</td></tr>
<tr><td>Exterior angle theorem</td><td>360° ÷ 3 sides = 120° per turn; verifies sum of exterior angles = 360°</td></tr>
</table>
</div>
</div>
</section>
<!-- ═══════════════════ 06 — COLOURED TRIANGLE ═══════════════════ -->
<section id="coloured-triangle">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>Coloured Triangle</h1>
<p class="lead">Draw a triangle where each side is a different colour — green, red, and blue — by changing <code>penColor</code> between sides.</p>
<button class="complete-btn" data-id="coloured-triangle" onclick="toggleComplete(this)"><span class="btn-icon">○</span> Mark as Complete</button>
</div>
<div class="article">
<h2>Your Task</h2>
<p>Use three pens (or change the colour on one pen before each side) to produce a triangle with sides in three different colours.</p>
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Swift</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="kw">var</span> <span class="vr">p</span> = <span class="tp">Pen</span>()
<span class="vr">p</span>.<span class="fn">penColor</span> = .<span class="fn">green</span>
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">150</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">120</span>)
<span class="cm">// Continue for red and blue sides…</span>
<span class="fn">addShape</span>(pen: <span class="vr">p</span>)</pre>
</div>
<div class="img-wrap">
<img src="images/02-06-coloured-triangle.png" alt="Coloured triangle">
</div>
<button class="solution-toggle" onclick="toggleSolution(this,'sol-coloured-triangle')">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
Show Solution
</button>
<blockquote><strong>Colour is a pen <em>state</em>.</strong> When you set <code>p.penColor = .red</code>, it's not drawing anything yet — it's just updating the pen's "current colour" setting. The <em>next</em> <code>addLine</code> you call will use that colour. This is the same pattern as position and heading: the pen keeps track of its current state, and each drawing command uses whatever state is active when you call it. Change the state between lines to get multi-coloured shapes.</blockquote>
<div class="solution-body" id="sol-coloured-triangle">
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Swift</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="kw">var</span> <span class="vr">p</span> = <span class="tp">Pen</span>()
<span class="vr">p</span>.<span class="fn">penColor</span> = .<span class="fn">green</span>
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">150</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">120</span>)
<span class="vr">p</span>.<span class="fn">penColor</span> = .<span class="fn">red</span>
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">150</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">120</span>)
<span class="vr">p</span>.<span class="fn">penColor</span> = .<span class="fn">blue</span>
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">150</span>)
<span class="fn">addShape</span>(pen: <span class="vr">p</span>)</pre>
</div>
</div>
<div class="im-table-wrap">
<div class="im-table-header">Curriculum Connections</div>
<table>
<tr><th>Concept</th><th>Connection</th></tr>
<tr><td>Triangle classification</td><td>Equilateral — three sides equal, three angles equal (60° each)</td></tr>
<tr><td>Angle sum</td><td>Interior angles of any triangle sum to 180°</td></tr>
</table>
</div>
</div>
</section>
<!-- ═══════════════════ 07 — DIAMOND ═══════════════════ -->
<section id="diamond">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>Diamond</h1>
<p class="lead">Draw a diamond (rhombus) with equal sides but non-right angles — using turn angles less than and greater than 90°.</p>
<button class="complete-btn" data-id="diamond" onclick="toggleComplete(this)"><span class="btn-icon">○</span> Mark as Complete</button>
</div>
<div class="article">
<h2>Your Task</h2>
<p>Draw a diamond with side length 150 and interior angles of 60° and 120°. Hint: the exterior turns will be 120° and 60° alternating.</p>
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Swift</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="kw">var</span> <span class="vr">p</span> = <span class="tp">Pen</span>()
<span class="cm">// 4 equal sides, alternating turns</span>
<span class="fn">addShape</span>(pen: <span class="vr">p</span>)</pre>
</div>
<div class="img-wrap">
<img src="images/02-07-diamond.png" alt="Diamond">
</div>
<button class="solution-toggle" onclick="toggleSolution(this,'sol-diamond')">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
Show Solution
</button>
<blockquote><strong>Why two different turn angles?</strong> A rhombus has 4 equal sides but <em>two different interior angles</em> — 60° and 120° — that alternate around the shape. The exterior angle at each corner is <code>180° − interior</code>, so the exterior angles alternate between <code>180° − 60° = 120°</code> and <code>180° − 120° = 60°</code>. Those are exactly the turn values in the solution below. Check the sanity: <code>120° + 60° + 120° + 60° = 360°</code> — one full rotation, so the path closes. ✓</blockquote>
<blockquote><strong>Adjacent angles are supplementary.</strong> In <em>any</em> parallelogram (including rhombuses), adjacent interior angles sum to 180°. So if one angle is 60°, the next one around must be 120°, and then back to 60°, and so on. This is a direct consequence of the parallel sides: imagine extending one side as a transversal — the co-interior angles with the next side must sum to 180°.</blockquote>
<div class="solution-body" id="sol-diamond">
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Swift</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="kw">var</span> <span class="vr">p</span> = <span class="tp">Pen</span>()
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">45</span>) <span class="cm">// tilt the rhombus so it stands on a corner</span>
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">150</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">60</span>)
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">150</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">120</span>)
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">150</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">60</span>)
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">150</span>)
<span class="fn">addShape</span>(pen: <span class="vr">p</span>)</pre>
</div>
</div>
<div class="im-table-wrap">
<div class="im-table-header">Curriculum Connections</div>
<table>
<tr><th>Concept</th><th>Connection</th></tr>
<tr><td>Rhombus properties</td><td>4 equal sides; opposite angles equal; diagonals bisect each other at right angles</td></tr>
<tr><td>Supplementary angles</td><td>Adjacent interior angles sum to 180°: 60° + 120° = 180°</td></tr>
</table>
</div>
</div>
</section>
<!-- ═══════════════════ 08 — FILL IT IN ═══════════════════ -->
<section id="fill-it-in">
<div class="section-hero">
<span class="section-tag tutorial">◆ Tutorial</span>
<h1>Fill It In</h1>
<p class="lead">Learn about the <code>fillColor</code> property to colour the interior of closed shapes.</p>
<button class="complete-btn" data-id="fill-it-in" onclick="toggleComplete(this)"><span class="btn-icon">○</span> Mark as Complete</button>
</div>
<div class="article">
<h2>Adding Fill</h2>
<p>Setting <code>fillColor</code> on a pen before drawing will colour the enclosed area of a closed shape. The path must be closed (return to its starting point) for fill to work correctly.</p>
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Swift</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="kw">var</span> <span class="vr">p</span> = <span class="tp">Pen</span>()
<span class="vr">p</span>.<span class="fn">fillColor</span> = .<span class="fn">yellow</span>
<span class="vr">p</span>.<span class="fn">penColor</span> = .<span class="fn">orange</span>
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="fn">addShape</span>(pen: <span class="vr">p</span>)</pre>
</div>
<blockquote><strong>Fill vs stroke.</strong> <code>fillColor</code> paints the <em>interior</em> of a closed shape; <code>penColor</code> (also called "stroke") paints the <em>boundary line</em>. You can set both, neither, or just one — giving you a yellow square with an orange outline, a pure yellow fill with no border (set <code>penColor</code> to match <code>fillColor</code>), or just an outline with no fill. This is the same distinction every vector graphics tool uses.</blockquote>
<blockquote><strong>Area vs perimeter.</strong> The fill occupies the <strong>area</strong> (<code>100 × 100 = 10,000</code> square units for this square); the pen line traces the <strong>perimeter</strong> (<code>4 × 100 = 400</code> units). These are the two fundamental measurements of a 2D shape. Perimeter is a length (measured in units); area is an area (measured in square units).</blockquote>
<blockquote><strong>"Closed" matters.</strong> Fill only works if the path forms a closed loop — i.e., the last point connects back to the first. An unclosed path (three sides of a square with the fourth side missing) can't be filled because the rendering system doesn't know what counts as "inside". This is a property of plane topology: a closed curve divides the plane into exactly two regions (inside and outside), but an open curve doesn't.</blockquote>
<div class="img-wrap">
<img src="images/02-08-fill-it-in.png" alt="Fill it in">
</div>
<div class="im-table-wrap">
<div class="im-table-header">Curriculum Connections</div>
<table>
<tr><th>Concept</th><th>Connection</th></tr>
<tr><td>Area vs perimeter</td><td>Fill occupies the interior (area); the pen line defines the boundary (perimeter)</td></tr>
<tr><td>Closed figures</td><td>A shape must be topologically closed for fill to render — a key property in geometry</td></tr>
</table>
</div>
</div>
</section>
<!-- ═══════════════════ 09 — COLOURED SQUARES ═══════════════════ -->
<section id="coloured-squares">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>Coloured Squares</h1>
<p class="lead">Draw three filled squares in a row — red, green, and blue — each 80 units wide with a 20-unit gap between them.</p>
<button class="complete-btn" data-id="coloured-squares" onclick="toggleComplete(this)"><span class="btn-icon">○</span> Mark as Complete</button>
</div>
<div class="article">
<h2>Your Task</h2>
<p>Use three separate pens positioned at different x-coordinates. Give each pen a different <code>fillColor</code>.</p>
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Swift</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="cm">// Three pens at x = 0, 100, 200</span>
<span class="cm">// Each draws an 80×80 filled square</span></pre>
</div>
<div class="img-wrap">
<img src="images/02-09-coloured-squares.png" alt="Coloured squares">
</div>
<button class="solution-toggle" onclick="toggleSolution(this,'sol-coloured-squares')">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
Show Solution
</button>
<blockquote><strong>Three pens, three starting positions.</strong> Each <code>Pen()</code> begins at the origin — <em>your</em> job is to move it to the right starting position before drawing. For a row of squares at x = 0, 100, 200, the second pen needs <code>move(distance: 100)</code> and the third needs <code>move(distance: 200)</code>. Note the 20-unit gap: square 1 ends at x = 80, square 2 starts at x = 100, giving a 20-unit space between them.</blockquote>
<blockquote><strong>Notice the repetition.</strong> The three blocks are nearly identical except for the move distance and the fill colour. This is a perfect candidate for a <em>loop</em> (Chapter III!) and then a <em>function</em> (Chapter V!) — but with only variables and conditionals available so far, you have to write it out longhand. Feel the pain of the repetition; that pain is exactly what loops and functions solve.</blockquote>
<div class="solution-body" id="sol-coloured-squares">
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Swift</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="kw">var</span> <span class="vr">p1</span> = <span class="tp">Pen</span>()
<span class="vr">p1</span>.<span class="fn">fillColor</span> = .<span class="fn">red</span>
<span class="vr">p1</span>.<span class="fn">addLine</span>(distance: <span class="num">80</span>)
<span class="vr">p1</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">p1</span>.<span class="fn">addLine</span>(distance: <span class="num">80</span>)
<span class="vr">p1</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">p1</span>.<span class="fn">addLine</span>(distance: <span class="num">80</span>)
<span class="vr">p1</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">p1</span>.<span class="fn">addLine</span>(distance: <span class="num">80</span>)
<span class="fn">addShape</span>(pen: <span class="vr">p1</span>)
<span class="kw">var</span> <span class="vr">p2</span> = <span class="tp">Pen</span>()
<span class="vr">p2</span>.<span class="fn">move</span>(distance: <span class="num">100</span>)
<span class="vr">p2</span>.<span class="fn">fillColor</span> = .<span class="fn">green</span>
<span class="vr">p2</span>.<span class="fn">addLine</span>(distance: <span class="num">80</span>)
<span class="vr">p2</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">p2</span>.<span class="fn">addLine</span>(distance: <span class="num">80</span>)
<span class="vr">p2</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">p2</span>.<span class="fn">addLine</span>(distance: <span class="num">80</span>)
<span class="vr">p2</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">p2</span>.<span class="fn">addLine</span>(distance: <span class="num">80</span>)
<span class="fn">addShape</span>(pen: <span class="vr">p2</span>)
<span class="kw">var</span> <span class="vr">p3</span> = <span class="tp">Pen</span>()
<span class="vr">p3</span>.<span class="fn">move</span>(distance: <span class="num">200</span>)
<span class="vr">p3</span>.<span class="fn">fillColor</span> = .<span class="fn">blue</span>
<span class="vr">p3</span>.<span class="fn">addLine</span>(distance: <span class="num">80</span>)
<span class="vr">p3</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">p3</span>.<span class="fn">addLine</span>(distance: <span class="num">80</span>)
<span class="vr">p3</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">p3</span>.<span class="fn">addLine</span>(distance: <span class="num">80</span>)
<span class="vr">p3</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">p3</span>.<span class="fn">addLine</span>(distance: <span class="num">80</span>)
<span class="fn">addShape</span>(pen: <span class="vr">p3</span>)</pre>
</div>
</div>
<div class="im-table-wrap">
<div class="im-table-header">Curriculum Connections</div>
<table>
<tr><th>Concept</th><th>Connection</th></tr>
<tr><td>Area</td><td>Each square: area = 80² = 6400 square units; total area = 3 × 6400 = 19,200</td></tr>
<tr><td>Translations</td><td>Each square is a translated copy — same shape, size, and orientation at a different position</td></tr>
</table>
</div>
</div>
</section>
<!-- ═══════════════════ 10 — VARIABLES ═══════════════════ -->
<section id="variables">
<div class="section-hero">
<span class="section-tag tutorial">◆ Tutorial</span>
<h1>Variables</h1>
<p class="lead">Store sizes in variables so you can change your shape's dimensions in one place and have the whole drawing update automatically.</p>
<button class="complete-btn" data-id="variables" onclick="toggleComplete(this)"><span class="btn-icon">○</span> Mark as Complete</button>
</div>
<div class="article">
<h2>Using Variables for Dimensions</h2>
<p>A <strong>variable</strong> is a named container for a value. By storing a side length in a variable, changing it once updates the entire drawing — and the code becomes self-documenting because the name tells you what the number means.</p>
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Swift</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="kw">let</span> <span class="vr">side</span> = <span class="num">120.0</span> <span class="cm">// change this one value to resize everything</span>
<span class="kw">var</span> <span class="vr">p</span> = <span class="tp">Pen</span>()
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="vr">side</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="vr">side</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="vr">side</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="vr">side</span>)
<span class="fn">addShape</span>(pen: <span class="vr">p</span>)</pre>
</div>
<h2>Variables vs Constants</h2>
<p>You may have noticed two different keywords in Swift: <code>var</code> and <code>let</code>. They both name a value — but behave differently.</p>
<table>
<tr><th>Keyword</th><th>Name</th><th>Can it change?</th><th>Use it for…</th></tr>
<tr><td><code>var</code></td><td>Variable</td><td>Yes</td><td>Things that change over time — like a <code>Pen</code> as it moves and turns</td></tr>
<tr><td><code>let</code></td><td>Constant</td><td>No</td><td>Fixed values that should stay the same — like a side length you set once</td></tr>
</table>
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Swift</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="kw">let</span> <span class="vr">side</span> = <span class="num">100.0</span> <span class="cm">// constant — the value is fixed</span>
<span class="kw">var</span> <span class="vr">p</span> = <span class="tp">Pen</span>() <span class="cm">// variable — p changes as we call methods on it</span></pre>
</div>
<p>Use <code>let</code> when a value should never change after you set it — Swift will warn you if you accidentally try to modify it. Use <code>var</code> when the value needs to change (or when Swift requires it, as with <code>Pen</code>).</p>
<blockquote><strong>Why use variables at all?</strong> Three reasons: (1) <em>one place to change</em> — update <code>side</code> once and every <code>addLine(distance: side)</code> uses the new value; (2) <em>self-documenting code</em> — <code>side</code> tells the reader what <code>120.0</code> means in context, whereas bare numbers don't; (3) <em>expressions</em> — you can compute derived values like <code>let perimeter = 4 * side</code> without manually recalculating.</blockquote>
<blockquote><strong>Variables are like letters in algebra.</strong> In maths you write "let <em>s</em> be the side length" and then use <em>s</em> everywhere: perimeter = 4<em>s</em>, area = <em>s</em>². Swift's <code>let side = 100.0</code> is literally the same idea — you're binding a name to a value and reasoning about it symbolically. This is the bridge from <em>specific numbers</em> (arithmetic) to <em>general patterns</em> (algebra).</blockquote>
<blockquote><strong>Why default to <code>let</code>?</strong> When Swift sees <code>let x = 10</code>, it <em>guarantees</em> that <code>x</code> never changes. This guarantee means you (and anyone reading your code) can trust that every reference to <code>x</code> has the same value. Using <code>var</code> gives up that guarantee. Rule of thumb: <strong>start with <code>let</code>, and only switch to <code>var</code> if Swift tells you the variable needs to change</strong>. The fewer things that can change, the easier it is to reason about your program.</blockquote>
<blockquote><strong>Types are inferred.</strong> When you write <code>let side = 100.0</code>, Swift figures out that <code>side</code> is a <code>Double</code> (because of the decimal point). If you wrote <code>let side = 100</code> (no decimal), it would be an <code>Int</code>. This matters: <code>addLine(distance:)</code> expects a <code>Double</code>, so writing <code>let side = 100</code> (Int) would be a type error. Writing <code>100.0</code> (Double) works directly. Small distinction, big difference!</blockquote>
<div class="im-table-wrap">
<div class="im-table-header">Curriculum Connections</div>
<table>
<tr><th>Concept</th><th>Connection</th></tr>
<tr><td>Variables & expressions</td><td>Side length <em>s</em> is a variable; perimeter = 4s and area = s² are expressions derived from it</td></tr>
<tr><td>Generalisation</td><td>Writing a formula in terms of a variable generalises from specific numbers to all cases</td></tr>
</table>
</div>
</div>
</section>
<!-- ═══ Sections 11–21: Exercise stubs ═══ -->
<!-- 11 — HOUSE -->
<section id="house">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>House</h1>
<p class="lead">Combine a square base and a triangular roof to draw a simple house shape using two pens or careful repositioning.</p>
<button class="complete-btn" data-id="house" onclick="toggleComplete(this)"><span class="btn-icon">○</span> Mark as Complete</button>
</div>
<div class="article">
<h2>Your Task</h2>
<p>Draw a square (100 units) for the walls, then continue from the top-left corner to draw an isosceles triangle roof. The roof peak should be centred above the square.</p>
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Swift</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="kw">var</span> <span class="vr">p</span> = <span class="tp">Pen</span>()
<span class="cm">// Square body + triangular roof</span>
<span class="fn">addShape</span>(pen: <span class="vr">p</span>)</pre>
</div>
<div class="img-wrap">
<img src="images/02-11-house.png" alt="House">
</div>
<button class="solution-toggle" onclick="toggleSolution(this,'sol-house')">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
Show Solution
</button>
<blockquote><strong>Composite figures.</strong> A house is a <em>composite</em> of two basic shapes: a square (the body) and a triangle (the roof) sitting on top. Breaking a complex shape into simple parts is a core problem-solving technique in geometry — you calculate area, perimeter, and properties of each part separately, then combine. Cities, circuit boards, molecules, and computer graphics are all built from composites of simpler parts.</blockquote>
<blockquote><strong>The mysterious <code>57.74</code>.</strong> This is the side length of an equilateral triangle with the <em>same base as the square</em>. An equilateral triangle with side <code>s</code> has a height of <code>s × √3 / 2 ≈ 0.866 × s</code>. If the square has side 100, an equilateral roof would have sides of 100 each — but the code uses 57.74, which is actually <code>100 / √3</code>. This makes the roof an <em>isosceles</em> (not equilateral) triangle with a 120° apex and 30° base angles — a flatter roof. If you wanted an equilateral roof (60°-60°-60°, a steeper pitch), you'd use side length 100 with a 60° first turn.</blockquote>
<div class="solution-body" id="sol-house">
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Swift</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="kw">var</span> <span class="vr">p</span> = <span class="tp">Pen</span>()
<span class="cm">// Square base (100 × 100)</span>
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="cm">// Move up to the top-left of the square (without drawing)</span>
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">p</span>.<span class="fn">move</span>(distance: <span class="num">100</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: -<span class="num">90</span>)
<span class="cm">// Roof: two sides at 30° from horizontal, meeting at a 120° apex</span>
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">30</span>)
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">57.74</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">120</span>)
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">57.74</span>)
<span class="fn">addShape</span>(pen: <span class="vr">p</span>)</pre>
</div>
</div>
<div class="im-table-wrap">
<div class="im-table-header">Curriculum Connections</div>
<table>
<tr><th>Concept</th><th>Connection</th></tr>
<tr><td>Composite figures</td><td>Total area = area of square + area of triangle — composites are decomposed into simpler shapes</td></tr>
<tr><td>Isosceles triangle</td><td>Roof triangle has two equal sides and two equal base angles</td></tr>
</table>
</div>
</div>
</section>
<!-- 12 — CALCULATE -->
<section id="calculate">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>Calculate</h1>
<p class="lead">Use Swift arithmetic to compute side lengths and angles — let the code do the maths rather than calculating by hand.</p>
<button class="complete-btn" data-id="calculate" onclick="toggleComplete(this)"><span class="btn-icon">○</span> Mark as Complete</button>
</div>
<div class="article">
<h2>Your Task</h2>
<p>Draw a regular hexagon. Instead of calculating the turn angle yourself, store the number of sides in a constant and use <code>360.0 / 6</code> to let Swift compute it. Then write one <code>addLine</code> and one <code>turn</code> for each of the six sides.</p>
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Swift</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="kw">let</span> <span class="vr">sides</span> = <span class="num">6</span>
<span class="kw">let</span> <span class="vr">turn</span> = <span class="num">360.0</span> / <span class="tp">Double</span>(<span class="vr">sides</span>)
<span class="kw">var</span> <span class="vr">p</span> = <span class="tp">Pen</span>()
<span class="cm">// Draw each of the 6 sides using 'turn'</span>
<span class="fn">addShape</span>(pen: <span class="vr">p</span>)</pre>
</div>
<div class="img-wrap">
<img src="images/02-12-calculate.png" alt="Calculate">
</div>
<button class="solution-toggle" onclick="toggleSolution(this,'sol-calculate')">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
Show Solution
</button>
<blockquote><strong>Let the code do the maths.</strong> Instead of calculating <code>360 ÷ 6 = 60</code> in your head and hardcoding <code>turn(degrees: 60)</code>, store the number of sides in a constant and compute <code>turn = 360.0 / Double(sides)</code>. Now changing <code>sides</code> to 8 automatically updates the turn to 45°. This is a huge pedagogical leap: you're moving from "doing arithmetic with specific numbers" to "expressing a general formula algebraically" — exactly the step students take when moving from arithmetic to algebra in school maths.</blockquote>
<blockquote><strong>Why <code>360.0</code> and not <code>360</code>?</strong> Because <code>Double(sides)</code> produces a <code>Double</code>, Swift needs the other side of the division to also be a <code>Double</code> for the types to match. Writing <code>360.0</code> (with the decimal point) makes it a <code>Double</code> literal. If you wrote <code>360</code> (no decimal), Swift would treat it as an <code>Int</code> and the division wouldn't compile because <code>Int / Double</code> is a type mismatch. This is the strict-typing theme you'll see again in Chapter III's spiral exercise.</blockquote>
<div class="solution-body" id="sol-calculate">
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Swift</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="kw">let</span> <span class="vr">sides</span> = <span class="num">6</span>
<span class="kw">let</span> <span class="vr">turn</span> = <span class="num">360.0</span> / <span class="tp">Double</span>(<span class="vr">sides</span>)
<span class="kw">var</span> <span class="vr">p</span> = <span class="tp">Pen</span>()
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="vr">turn</span>)
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="vr">turn</span>)
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="vr">turn</span>)
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="vr">turn</span>)
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="vr">turn</span>)
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="vr">turn</span>)
<span class="fn">addShape</span>(pen: <span class="vr">p</span>)</pre>
</div>
</div>
<div class="im-table-wrap">
<div class="im-table-header">Curriculum Connections</div>
<table>
<tr><th>Concept</th><th>Connection</th></tr>
<tr><td>Regular polygons</td><td>Exterior angle = 360° ÷ n; interior angle = 180° − (360° ÷ n)</td></tr>
<tr><td>Algebraic reasoning</td><td>Expressing the angle as 360/n generalises the formula for all regular polygons</td></tr>
</table>
</div>
</div>
</section>
<!-- 13 — VARIABLE HOUSE -->
<section id="variable-house">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>Variable House</h1>
<p class="lead">Refactor the House exercise using a variable for the house width, so you can resize the whole building by changing one number.</p>
<button class="complete-btn" data-id="variable-house" onclick="toggleComplete(this)"><span class="btn-icon">○</span> Mark as Complete</button>
</div>
<div class="article">
<h2>Your Task</h2>
<p>Store the house width in a variable <code>w</code>. The roof height and angles should be derived from <code>w</code> using arithmetic, so the shape scales correctly.</p>
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Swift</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="kw">let</span> <span class="vr">w</span> = <span class="num">120.0</span> <span class="cm">// change this to resize the house</span>
<span class="kw">var</span> <span class="vr">p</span> = <span class="tp">Pen</span>()
<span class="cm">// Use w throughout</span>
<span class="fn">addShape</span>(pen: <span class="vr">p</span>)</pre>
</div>
<blockquote><strong>Proportional scaling.</strong> This is the whole point of variable-based design: everything that depends on the house's size should be <em>derived from</em> <code>w</code>, not hardcoded. Roof side length = <code>w / sqrt(3)</code> (or <code>w</code> for an equilateral roof). Window position = <code>w * 0.3</code>. Door width = <code>w * 0.25</code>. Change <code>w</code> and every piece scales together, producing a larger or smaller but <strong>geometrically similar</strong> house. This "proportional design" pattern is foundational for every flag, house, and vehicle you'll build in later chapters.</blockquote>
<blockquote><strong>Angles don't scale.</strong> When you shrink a triangle, its <em>lengths</em> get smaller but its <em>angles</em> stay the same. That's what makes similar shapes similar. So your variable <code>w</code> multiplies every <code>addLine(distance: ...)</code>, but the <code>turn(degrees: ...)</code> values stay constant (60°, 120°, 90° etc). This directly mirrors the mathematical definition of similar figures: lengths scale by a common factor, angles are preserved.</blockquote>
<div class="img-wrap">
<img src="images/02-13-variable-house.png" alt="Variable house">
</div>
<div class="im-table-wrap">
<div class="im-table-header">Curriculum Connections</div>
<table>
<tr><th>Concept</th><th>Connection</th></tr>
<tr><td>Proportional reasoning</td><td>Scaling all dimensions by the same factor produces a <strong>similar</strong> figure</td></tr>
<tr><td>Variables in geometry</td><td>Writing perimeter/area formulas in terms of <em>w</em> models geometric relationships algebraically</td></tr>
</table>
</div>
</div>
</section>
<!-- 14 — RED CROSS -->
<section id="red-cross">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>Red Cross</h1>
<p class="lead">Draw a filled red cross (plus sign) shape — a composite figure made from rectangles.</p>
<button class="complete-btn" data-id="red-cross" onclick="toggleComplete(this)"><span class="btn-icon">○</span> Mark as Complete</button>
</div>
<div class="article">
<h2>Your Task</h2>
<p>A cross can be drawn as a 12-sided polygon. Start at the bottom-left of the lower arm and work around the perimeter, alternating between long (100) and short (40) sides, and alternating the <em>direction</em> of the turns (some are 90° left, some are 90° right).</p>
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Swift</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="kw">var</span> <span class="vr">p</span> = <span class="tp">Pen</span>()
<span class="vr">p</span>.<span class="fn">fillColor</span> = .<span class="fn">red</span>
<span class="vr">p</span>.<span class="fn">penColor</span> = .<span class="fn">red</span>
<span class="cm">// 12 sides, 4 outer corners (90°), 8 inner corners (-90°)</span>
<span class="fn">addShape</span>(pen: <span class="vr">p</span>)</pre>
</div>
<blockquote><strong>Convex vs concave polygons.</strong> A <strong>convex</strong> polygon has <em>all interior angles less than 180°</em> — every triangle, square, regular polygon, etc. A <strong>concave</strong> (or "non-convex") polygon has at least one interior angle greater than 180° — the cross is the classic example. You can spot a concave polygon because the boundary "bends inward" at some corner. The sum of interior angles still equals <code>(n − 2) × 180°</code>, but individual angles can exceed 180° (reflex angles) as long as others compensate.</blockquote>
<blockquote><strong>Sign of the turn.</strong> At the <em>outer</em> corners of the cross (the 4 points where the arms end), the pen turns 90° left — positive. At the <em>inner</em> corners (where an arm joins the centre square), it turns 90° right — negative. The total turning must still sum to 360° for the shape to close: <code>4 × 90° + 8 × (−90°) = 360° − 720° = −360°</code>. Wait, that's −360°, not +360°! That's fine — −360° also brings the pen back to its original heading. A concave polygon traced clockwise ends with total turning of −360°; traced anti-clockwise, +360°. Either way, it closes.</blockquote>
<blockquote><strong>Area via inclusion–exclusion.</strong> The cross is made of 3 overlapping rectangles: a horizontal bar (100 × 40), a vertical bar (40 × 100), and — wait, they overlap at a 40 × 40 square in the middle which would be counted twice. Total area = <code>(100 × 40) + (100 × 40) − (40 × 40) = 4000 + 4000 − 1600 = 6400</code> square units. This "inclusion–exclusion" trick — add the parts, subtract the overlap — is one of the most useful formulas in combinatorics and set theory.</blockquote>
<div class="img-wrap">
<img src="images/02-14-red-cross.png" alt="Red cross">
</div>
<div class="im-table-wrap">
<div class="im-table-header">Curriculum Connections</div>
<table>
<tr><th>Concept</th><th>Connection</th></tr>
<tr><td>Area of composite figures</td><td>Cross area = 3 rectangles overlapping; use inclusion-exclusion: 3(100×40) − 2(40×40)</td></tr>
<tr><td>Perimeter of irregular shapes</td><td>Count each boundary segment: 4 long sides + 8 short sides</td></tr>
</table>
</div>
</div>
</section>
<!-- 15 — SIMPLE SNOWFLAKE -->
<section id="simple-snowflake">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>Simple Snowflake</h1>
<p class="lead">Draw 6 arms radiating from the centre — each arm a straight line — to create a basic snowflake with 6-fold symmetry.</p>
<button class="complete-btn" data-id="simple-snowflake" onclick="toggleComplete(this)"><span class="btn-icon">○</span> Mark as Complete</button>
</div>
<div class="article">
<h2>Your Task</h2>
<p>Draw 6 arms of equal length, each rotated 60° from the last. After each arm, return to the centre by moving backwards (negative distance).</p>
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Swift</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="kw">var</span> <span class="vr">p</span> = <span class="tp">Pen</span>()
<span class="cm">// Arm 1</span>
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">p</span>.<span class="fn">move</span>(distance: -<span class="num">100</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">60</span>)
<span class="cm">// Arm 2</span>
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">p</span>.<span class="fn">move</span>(distance: -<span class="num">100</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">60</span>)
<span class="cm">// Arm 3</span>
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">p</span>.<span class="fn">move</span>(distance: -<span class="num">100</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">60</span>)
<span class="cm">// Arm 4</span>
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">p</span>.<span class="fn">move</span>(distance: -<span class="num">100</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">60</span>)
<span class="cm">// Arm 5</span>
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">p</span>.<span class="fn">move</span>(distance: -<span class="num">100</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">60</span>)
<span class="cm">// Arm 6</span>
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)