-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path01.html
More file actions
1289 lines (1139 loc) · 81.2 KB
/
01.html
File metadata and controls
1289 lines (1139 loc) · 81.2 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>Coordinate Geometry with Sequences — Geometry Playground</title>
<!-- SEO -->
<meta name="description" content="Chapter I of Geometry Playground: coordinate geometry through Swift sequences. Draw shapes with the Pen API, explore angles, and build geometric intuition on iPad or Mac." />
<meta name="keywords" content="Swift Playgrounds, coordinate geometry, sequences, Pen API, drawing shapes, angles, Swift for beginners, iPad coding, geometry chapter 1, IM1" />
<meta name="author" content="Daniel Budd" />
<meta name="robots" content="index, follow" />
<link rel="canonical" href="https://dbbudd.github.io/01.html" />
<!-- Open Graph -->
<meta property="og:type" content="article" />
<meta property="og:site_name" content="Geometry Playground" />
<meta property="og:title" content="Coordinate Geometry with Sequences — Geometry Playground" />
<meta property="og:description" content="Chapter I: coordinate geometry through Swift sequences. Draw shapes with the Pen API, explore angles, and build geometric intuition on iPad or Mac." />
<meta property="og:url" content="https://dbbudd.github.io/01.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="Coordinate Geometry with Sequences — Geometry Playground" />
<meta name="twitter:description" content="Chapter I: coordinate geometry through Swift sequences. Draw shapes with the Pen API, explore angles, and build geometric intuition 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": "Coordinate Geometry with Sequences — Geometry Playground Chapter I",
"description": "Coordinate geometry through Swift sequences. Draw shapes with the Pen API, explore angles, and build geometric intuition with Swift Playgrounds on iPad or Mac.",
"url": "https://dbbudd.github.io/01.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": "Coordinate Geometry, Pen API, Angle Measurement, Area and Perimeter, Basic Shapes, Sequences"
}
</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,
/* Scan both the intro .lead paragraphs and the main article
body. The walker automatically skips <code>, <pre>, <a>,
<script>, and <style> regardless of the selector. */
contentSelector: '.section-hero .lead, .article p, .article li'
/* Terms come from vocab/geometry.js, loaded in the next script
tag. Any inline `terms: { ... }` added here would override
entries from that file on a per-chapter basis. */
},
mobile: {
/* The library injects a burger menu + slide-out drawer on
mobile. These `sections` are cloned into the drawer so
students can jump between chapters and sections from a
small screen. */
drawer: {
sections: [
{ title: 'Chapters', clone: '#chapterPill .nav-dropdown' },
{ title: 'Sections', clone: '.sidebar nav' }
]
}
}
};
</script>
<!-- Load the shared vocabulary FIRST so window.CourseUI.vocab.terms
is populated by the time course-ui.js boots. -->
<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>
I
<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" class="current"><span class="dd-num">I</span> Coordinate Geometry</a>
<a href="02.html"><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">Intro to Pen</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 I</div>
<a href="#intro-to-pen" onclick="closePills()"><span class="dd-num">01</span> Intro to Pen</a>
<a href="#turning-corners" onclick="closePills()"><span class="dd-num">02</span> Turning Corners</a>
<a href="#squares" onclick="closePills()"><span class="dd-num">03</span> Squares</a>
<a href="#rectangles" onclick="closePills()"><span class="dd-num">04</span> Rectangles</a>
<a href="#more-squares" onclick="closePills()"><span class="dd-num">05</span> More Squares</a>
<a href="#triangle-in-square" onclick="closePills()"><span class="dd-num">06</span> Triangle in Square</a>
<a href="#up-and-down" onclick="closePills()"><span class="dd-num">07</span> Up and Down</a>
<a href="#multiple-shapes" onclick="closePills()"><span class="dd-num">08</span> Multiple Shapes</a>
<a href="#five-point-star" onclick="closePills()"><span class="dd-num">09</span> Five-Point Star</a>
<a href="#star-of-david" onclick="closePills()"><span class="dd-num">10</span> Star of David</a>
</div>
</div>
<!-- Progress -->
<div class="topbar-progress">
<span class="progress-text" id="progressText">0 / 8 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 I</div>
<nav id="sidebarNav">
<a href="#intro-to-pen" data-section="intro-to-pen">
<span class="nav-num">01</span>
<span>Intro to Pen<br><span class="nav-badge badge-tutorial">Tutorial</span></span>
<span class="nav-done">✓</span>
</a>
<a href="#turning-corners" data-section="turning-corners">
<span class="nav-num">02</span>
<span>Turning Corners<br><span class="nav-badge badge-tutorial">Tutorial</span></span>
<span class="nav-done">✓</span>
</a>
<a href="#squares" data-section="squares">
<span class="nav-num">03</span>
<span>Squares<br><span class="nav-badge badge-exercise">Exercise</span></span>
<span class="nav-done">✓</span>
</a>
<a href="#rectangles" data-section="rectangles">
<span class="nav-num">04</span>
<span>Rectangles<br><span class="nav-badge badge-exercise">Exercise</span></span>
<span class="nav-done">✓</span>
</a>
<a href="#more-squares" data-section="more-squares">
<span class="nav-num">05</span>
<span>More Squares<br><span class="nav-badge badge-exercise">Exercise</span></span>
<span class="nav-done">✓</span>
</a>
<a href="#triangle-in-square" data-section="triangle-in-square">
<span class="nav-num">06</span>
<span>Triangle in Square<br><span class="nav-badge badge-exercise">Exercise</span></span>
<span class="nav-done">✓</span>
</a>
<a href="#up-and-down" data-section="up-and-down">
<span class="nav-num">07</span>
<span>Up and Down<br><span class="nav-badge badge-tutorial">Tutorial</span></span>
<span class="nav-done">✓</span>
</a>
<a href="#multiple-shapes" data-section="multiple-shapes">
<span class="nav-num">08</span>
<span>Multiple Shapes<br><span class="nav-badge badge-exercise">Exercise</span></span>
<span class="nav-done">✓</span>
</a>
<a href="#five-point-star" data-section="five-point-star">
<span class="nav-num">09</span>
<span>Five-Point Star<br><span class="nav-badge badge-exercise">Exercise</span></span>
<span class="nav-done">✓</span>
</a>
<a href="#star-of-david" data-section="star-of-david">
<span class="nav-num">10</span>
<span>Star of David<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 I of VI</div>
<h1>Coordinate Geometry with Sequences</h1>
<p class="lead">Learn to draw with code using the <code style="background:rgba(255,255,255,0.15);color:#F2B13E">Pen</code> API. One command at a time, you'll lay down sequences of lines and turns to build squares, triangles, stars and more — and pick up the foundations of coordinate geometry along the way.</p>
<div class="banner-meta">
<div class="banner-stat"><span class="stat-num">10</span><span class="stat-label">Sections</span></div>
<div class="banner-stat"><span class="stat-num">2</span><span class="stat-label">Tutorials</span></div>
<div class="banner-stat"><span class="stat-num">8</span><span class="stat-label">Exercises</span></div>
</div>
</section>
<!-- ═══════════════════════════════════════════════════════
01 — INTRO TO PEN
═══════════════════════════════════════════════════════ -->
<section id="intro-to-pen">
<div class="section-hero">
<span class="section-tag tutorial">◆ Tutorial</span>
<h1>Intro to Pen</h1>
<p class="lead">Meet the <code>Pen</code> — your drawing tool. A pen starts at the origin (0, 0), faces right, and draws a line every time it moves forward.</p>
<div class="img-wrap">
<img src="images/00-intro-to-pen.png" alt="A single horizontal line drawn from the origin (0,0) using the Pen API in Geometry Playground">
</div>
<button class="complete-btn" data-id="intro-to-pen" onclick="toggleComplete(this)">
<span class="btn-icon">○</span> Mark as Complete
</button>
</div>
<div class="article">
<h2>The Pen API</h2>
<p>In this playground, you draw shapes using a <strong>Pen</strong> object. Picture yourself walking across a big sheet of paper while holding a pen to the ground — the pen has a <em>position</em> (where you are) and a <em>direction</em> (which way you're facing), and it draws a line every time you step forward.</p>
<blockquote><strong>💡 Coding tip.</strong> A <code>Pen</code> is a Swift <em>object</em>. We make one with <code>var p = Pen()</code> and then call <em>methods</em> on it using dot notation, like <code>p.addLine(...)</code>. The <code>var</code> keyword says "this variable may change" — and indeed every time you add a line, the pen's position and heading change.</blockquote>
<h3>Creating a Pen</h3>
<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">// Create a new pen at (0, 0), facing right</span>
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>) <span class="cm">// Move forward 100 units, drawing as you go</span>
<span class="fn">addShape</span>(pen: <span class="vr">p</span>) <span class="cm">// Render the shape on screen</span></pre>
</div>
<h3>Key Commands</h3>
<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">addLine</span>(distance: <span class="num">100</span>) <span class="cm">// Draw a line 100 units forward</span>
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>) <span class="cm">// Turn LEFT 90°</span>
<span class="vr">p</span>.<span class="fn">move</span>(distance: <span class="num">50</span>) <span class="cm">// Move 50 units without drawing</span>
<span class="vr">p</span>.<span class="fn">penColor</span> = .<span class="fn">red</span> <span class="cm">// Change line colour</span>
<span class="vr">p</span>.<span class="fn">lineWidth</span> = <span class="num">3</span> <span class="cm">// Change line thickness</span></pre>
</div>
<h3>Coordinate System</h3>
<p>The canvas uses a standard Cartesian coordinate system — <strong>x</strong> increases to the right, <strong>y</strong> increases upward. The pen starts at the origin <strong>(0, 0)</strong> and faces right (along the positive x-axis). <code>turn(degrees: 90)</code> rotates the pen <em>anti-clockwise</em> (a left turn).</p>
<blockquote><strong>📐 Maths tip.</strong> In maths class, angles are always measured anti-clockwise from the positive x-axis, and that's exactly what <code>turn</code> does. Positive angles go <em>left</em>; negative angles go <em>right</em>. This feels backwards at first because most people think "positive = clockwise", but the whole of mathematics disagrees with them — including your trig class and the unit circle.</blockquote>
<blockquote><strong>💡 Coding tip.</strong> Nothing appears on screen until you call <code>addShape(pen: p)</code>. Think of <code>addLine</code> and <code>turn</code> as giving the pen instructions — it remembers them, but it only draws when you ask it to show its work.</blockquote>
<div class="img-wrap">
<img src="images/01-intro-to-pen.png" alt="A single horizontal line drawn from the origin (0,0) using the Pen API in Geometry Playground">
</div>
<div class="callout">
<h3>💡 Think About It</h3>
<ul>
<li>What direction does the pen face at the start?</li>
<li>What happens if you call <code>addLine</code> twice without turning?</li>
<li>What coordinates does the pen reach after <code>addLine(distance: 100)</code>?</li>
</ul>
</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>The pen uses an (x, y) coordinate system — moving right increases x; the starting position is the <strong>origin (0, 0)</strong></td></tr>
<tr><td>Directed distance</td><td><code>addLine(distance:)</code> moves the pen a <strong>directed</strong> amount — length and direction both matter</td></tr>
<tr><td>Geometric definitions</td><td>A line segment has two endpoints; every call to <code>addLine</code> creates a segment between the current and new pen positions</td></tr>
</table>
</div>
</div>
</section>
<!-- ═══════════════════════════════════════════════════════
02 — TURNING CORNERS
═══════════════════════════════════════════════════════ -->
<section id="turning-corners">
<div class="section-hero">
<span class="section-tag tutorial">◆ Tutorial</span>
<h1>Turning Corners</h1>
<p class="lead">Explore <code>turn(degrees:)</code> — and discover how exterior angles and interior angles relate in any polygon.</p>
<button class="complete-btn" data-id="turning-corners" onclick="toggleComplete(this)">
<span class="btn-icon">○</span> Mark as Complete
</button>
</div>
<div class="article">
<h2>Angles and Turning</h2>
<p>The <code>turn</code> command rotates the pen in place without moving it. Positive degrees turn <strong>left</strong> (anti-clockwise); negative degrees turn <strong>right</strong> (clockwise).</p>
<blockquote><strong>🚶 Walk it out.</strong> Imagine walking along a line and then reaching a corner. You stop, swivel on the spot, and start walking again. That swivel is what <code>turn</code> does — it changes where you're facing but not where you are. The amount you swivel is measured in degrees.</blockquote>
<div class="img-wrap">
<img src="images/02-turning-corners.png" alt="Demonstration of angles and turning in Geometry Playground">
</div>
<h3>Interior vs. Exterior Angles</h3>
<p>When the pen draws a polygon, the angle you pass to <code>turn</code> is the <strong>exterior angle</strong> — the supplement of the interior angle.</p>
<ul>
<li><strong>Interior angle:</strong> the angle inside the polygon at each vertex</li>
<li><strong>Exterior angle:</strong> the supplement — how much you turn to keep walking along the boundary</li>
<li>For any convex polygon: <strong>interior + exterior = 180°</strong></li>
</ul>
<h3>Angle Classification</h3>
<ul>
<li><strong>Acute</strong> — less than 90°</li>
<li><strong>Right</strong> — exactly 90°</li>
<li><strong>Obtuse</strong> — between 90° and 180°</li>
<li><strong>Straight</strong> — exactly 180°</li>
<li><strong>Reflex</strong> — greater than 180°</li>
</ul>
<h3>The Sum of Exterior Angles</h3>
<p>For <em>any</em> convex polygon, the exterior angles add up to exactly <strong>360°</strong> — one full rotation. This is why, after drawing a closed shape, the pen always faces its original direction.</p>
<blockquote><strong>🚶 Walk it out.</strong> If you walked all the way around the boundary of a closed polygon and came back to your starting point facing the same way, you must have turned a total of 360° — one full revolution. This is true for a triangle, a square, a pentagon, a wobbly irregular hexagon, or even an 11-sided monster. The number of corners doesn't matter — only the total turning does.</blockquote>
<blockquote><strong>📐 Maths tip.</strong> The <em>interior</em> angle of a polygon lives <em>inside</em> the shape at a corner. The <em>exterior</em> angle is its supplement (interior + exterior = 180°). The code tells the pen how much to <em>turn</em>, which is the exterior angle — not the interior one. This trips up almost everybody the first time.</blockquote>
<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">// A right turn (clockwise): use a negative angle</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="num">90</span>) <span class="cm">// Turn RIGHT 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 class="im-table-wrap">
<div class="im-table-header">Curriculum Connections</div>
<table>
<tr><th>Concept</th><th>Connection</th></tr>
<tr><td>Angle classification</td><td>Turns of 90°, 120°, 144° etc. correspond to <strong>right</strong>, <strong>obtuse</strong>, and <strong>obtuse</strong> exterior angles</td></tr>
<tr><td>Supplementary angles</td><td>Interior angle + exterior angle = <strong>180°</strong> — they are supplementary</td></tr>
<tr><td>Sum of exterior angles</td><td>The pen always rotates a total of <strong>360°</strong> to return to its starting direction</td></tr>
</table>
</div>
</div>
</section>
<!-- ═══════════════════════════════════════════════════════
03 — SQUARES
═══════════════════════════════════════════════════════ -->
<section id="squares">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>Squares</h1>
<p class="lead">Draw a square with side length 100. A square has 4 equal sides and 4 right angles — so each turn is <strong>90°</strong>.</p>
<button class="complete-btn" data-id="squares" onclick="toggleComplete(this)">
<span class="btn-icon">○</span> Mark as Complete
</button>
</div>
<div class="article">
<h2>Your Task</h2>
<p>Draw a square with side length 100 using the Pen API. Remember: a square has 4 sides and turns of 90° at each corner.</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">// Your code here — 4 lines, 4 turns</span>
<span class="fn">addShape</span>(pen: <span class="vr">p</span>)</pre>
</div>
<h2>Mathematical Concepts</h2>
<h3>Properties of a Square</h3>
<ul>
<li>4 equal sides</li>
<li>4 right angles (90° each)</li>
<li>Perimeter = 4 × side length</li>
<li>Area = side² = <strong>100² = 10,000 square units</strong></li>
<li>Sum of exterior angles = 4 × 90° = 360° ✓</li>
</ul>
<h3>Quadrilateral Definition</h3>
<p>A square is a special <strong>rectangle</strong> (all angles 90°), which is a special <strong>parallelogram</strong> (opposite sides parallel), which is a special <strong>quadrilateral</strong> (4-sided polygon).</p>
<blockquote><strong>📐 Maths tip.</strong> The interior angle of a square is 90°, so its exterior angle is 180° − 90° = 90°. It's one of the very few polygons where the interior and exterior angles happen to be equal. Don't let that coincidence fool you — in every other polygon, they're different.</blockquote>
<blockquote><strong>💡 Coding tip.</strong> Notice that you're writing the same two lines over and over: <code>addLine</code> then <code>turn</code>. Programmers hate repetition — it's error-prone and boring to type. In Chapter III you'll meet the <code>for</code> loop, which lets you write "do this four times" in one line. For now, practice the long way — it builds your intuition for what the loop will eventually replace.</blockquote>
<div class="img-wrap">
<img src="images/03-squares.png" alt="A square is a special rectangle (all angles are 90 degrees)">
</div>
<button class="solution-toggle" onclick="toggleSolution(this,'sol-squares')">
<svg width="12" height="7" viewBox="0 0 12 7" fill="none"><path d="M1 1l5 5 5-5" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/></svg>
Show Solution
</button>
<div class="solution-body" id="sol-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="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>)
<span class="cm">// 4 × 90° = 360° — the pen faces its original direction again</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>Quadrilateral properties</td><td>A square is a <strong>regular quadrilateral</strong> — all sides equal, all angles 90°</td></tr>
<tr><td>Perimeter & area</td><td>P = 4s = 400; A = s² = 10,000 sq units</td></tr>
<tr><td>Sum of exterior angles</td><td>4 × 90° = 360° — the pen makes one complete rotation</td></tr>
</table>
</div>
</div>
</section>
<!-- ═══════════════════════════════════════════════════════
04 — RECTANGLES
═══════════════════════════════════════════════════════ -->
<section id="rectangles">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>Rectangles</h1>
<p class="lead">Draw a rectangle that is 100 units wide and 200 units tall. Rectangles have two pairs of equal sides — so the distances <em>alternate</em> between the width and height.</p>
<button class="complete-btn" data-id="rectangles" onclick="toggleComplete(this)">
<span class="btn-icon">○</span> Mark as Complete
</button>
</div>
<div class="article">
<h2>Your Task</h2>
<p>Draw a 100 × 200 rectangle. The pen still turns 90° at each corner, but now the side lengths alternate.</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 sides, alternating 100 and 200</span>
<span class="fn">addShape</span>(pen: <span class="vr">p</span>)</pre>
</div>
<h2>Mathematical Concepts</h2>
<h3>Rectangle Properties</h3>
<ul>
<li>2 pairs of equal parallel sides</li>
<li>4 right angles (90° each)</li>
<li>Perimeter = 2(width + height) = 2(100 + 200) = <strong>600 units</strong></li>
<li>Area = width × height = 100 × 200 = <strong>20,000 square units</strong></li>
</ul>
<blockquote><strong>📐 Maths tip.</strong> Why do opposite sides of a rectangle come out parallel when you draw it? Because you turn by the <em>same</em> angle (90°) at every corner — after two turns, you've swung around 180°, so side 3 points in exactly the opposite direction of side 1. Equal turns produce parallel sides. This is a tiny result you'll meet again as the Alternate Interior Angles theorem.</blockquote>
<blockquote><strong>💡 Coding tip.</strong> The two different side lengths (100 and 200) appear several times in the code. If you wanted to change the rectangle's size, you'd have to update each number individually — and it's easy to miss one. In Chapter II you'll learn to store numbers in <em>variables</em> like <code>let width = 100</code>, so one edit changes the whole shape.</blockquote>
<div class="img-wrap">
<img src="images/04-rectangles.png" alt="A rectangle">
</div>
<button class="solution-toggle" onclick="toggleSolution(this,'sol-rect')">
<svg width="12" height="7" viewBox="0 0 12 7" fill="none"><path d="M1 1l5 5 5-5" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/></svg>
Show Solution
</button>
<div class="solution-body" id="sol-rect">
<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">addLine</span>(distance: <span class="num">100</span>) <span class="cm">// bottom</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="cm">// right 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="num">100</span>) <span class="cm">// top</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="cm">// left side</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>Rectangle properties</td><td>Opposite sides are <strong>equal and parallel</strong>; all angles are 90°</td></tr>
<tr><td>Perimeter formula</td><td>P = 2(w + h) = 2(100 + 200) = <strong>600</strong></td></tr>
<tr><td>Area formula</td><td>A = w × h = <strong>20,000 sq units</strong></td></tr>
</table>
</div>
</div>
</section>
<!-- ═══════════════════════════════════════════════════════
05 — MORE SQUARES
═══════════════════════════════════════════════════════ -->
<section id="more-squares">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>More Squares</h1>
<p class="lead">Draw three nested squares with side lengths 50, 100, and 150. They all share the same starting point — creating a nested, concentric pattern.</p>
<button class="complete-btn" data-id="more-squares" onclick="toggleComplete(this)">
<span class="btn-icon">○</span> Mark as Complete
</button>
</div>
<div class="article">
<h2>Your Task</h2>
<p>Draw three squares: side lengths 50, 100, and 150. Each starts from the same origin point. Use a single Pen and draw them one after the other.</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">pen</span> = <span class="tp">Pen</span>()
<span class="cm">// Square 1: side 50</span>
<span class="cm">// Square 2: side 100</span>
<span class="cm">// Square 3: side 150</span>
<span class="fn">addShape</span>(pen: <span class="vr">pen</span>)</pre>
</div>
<h2>Mathematical Concepts</h2>
<h3>Similar Figures</h3>
<p>The three squares are <strong>similar figures</strong> — they have the same shape but different sizes. In similar figures:</p>
<ul>
<li>Corresponding angles are <strong>equal</strong></li>
<li>Corresponding side lengths are in the same <strong>ratio</strong></li>
<li>The scale factor from the 50-unit to the 100-unit square is <strong>2</strong>; from 50 to 150 is <strong>3</strong></li>
</ul>
<p>Any two squares are always similar — all squares have 90° angles and all sides are equal.</p>
<blockquote><strong>📐 Maths tip.</strong> When the side length of a square doubles, the <em>perimeter</em> doubles (×2), but the <em>area</em> quadruples (×4 = 2²). When it triples, the area grows ×9 = 3². This is the rule that scale factor <em>k</em> in a linear dimension produces scale factor <em>k²</em> in area. You'll see this again in Chapter V when we scale shapes on purpose.</blockquote>
<blockquote><strong>💡 Coding tip.</strong> Notice we're reusing a single pen variable called <code>pen</code> for all three squares. After each square, the pen returns to <code>(0, 0)</code> facing right (four 90° turns = 360°), so the next square starts exactly where the last one did — that's what creates the nested look.</blockquote>
<div class="img-wrap">
<img src="images/05-more-squares.png" alt="A rectangle">
</div>
<button class="solution-toggle" onclick="toggleSolution(this,'sol-more-sq')">
<svg width="12" height="7" viewBox="0 0 12 7" fill="none"><path d="M1 1l5 5 5-5" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/></svg>
Show Solution
</button>
<div class="solution-body" id="sol-more-sq">
<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">pen</span> = <span class="tp">Pen</span>()
<span class="cm">// Square 1: side 50</span>
<span class="vr">pen</span>.<span class="fn">addLine</span>(distance: <span class="num">50</span>)
<span class="vr">pen</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">pen</span>.<span class="fn">addLine</span>(distance: <span class="num">50</span>)
<span class="vr">pen</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">pen</span>.<span class="fn">addLine</span>(distance: <span class="num">50</span>)
<span class="vr">pen</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">pen</span>.<span class="fn">addLine</span>(distance: <span class="num">50</span>)
<span class="vr">pen</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="cm">// Square 2: side 100</span>
<span class="vr">pen</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">pen</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">pen</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">pen</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">pen</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">pen</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">pen</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">pen</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="cm">// Square 3: side 150</span>
<span class="vr">pen</span>.<span class="fn">addLine</span>(distance: <span class="num">150</span>)
<span class="vr">pen</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">pen</span>.<span class="fn">addLine</span>(distance: <span class="num">150</span>)
<span class="vr">pen</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">pen</span>.<span class="fn">addLine</span>(distance: <span class="num">150</span>)
<span class="vr">pen</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">pen</span>.<span class="fn">addLine</span>(distance: <span class="num">150</span>)
<span class="vr">pen</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="fn">addShape</span>(pen: <span class="vr">pen</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>Similar figures</td><td>All three squares are <strong>similar</strong> — same angles, proportional sides</td></tr>
<tr><td>Scale factor</td><td>50→100 scale factor = <strong>2</strong>; 50→150 = <strong>3</strong></td></tr>
<tr><td>Geometric patterns</td><td>Nesting similar figures at a common vertex reveals <strong>proportional growth</strong></td></tr>
</table>
</div>
</div>
</section>
<!-- ═══════════════════════════════════════════════════════
06 — TRIANGLE IN SQUARE
═══════════════════════════════════════════════════════ -->
<section id="triangle-in-square">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>Triangle in Square</h1>
<p class="lead">Draw an equilateral triangle (side 100) and a square (side 100) sharing the same base. Discover how the turn angles differ between polygons.</p>
<button class="complete-btn" data-id="triangle-in-square" 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 and a square, both with side length 100. You can share the first side, or draw them as separate shapes next to each other.</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">triangle</span> = <span class="tp">Pen</span>()
<span class="cm">// Equilateral triangle — 3 sides, 120° turns</span>
<span class="kw">var</span> <span class="vr">square</span> = <span class="tp">Pen</span>()
<span class="cm">// Square — 4 sides, 90° turns</span>
<span class="fn">addShape</span>(pen: <span class="vr">triangle</span>)
<span class="fn">addShape</span>(pen: <span class="vr">square</span>)</pre>
</div>
<h2>Mathematical Concepts</h2>
<h3>Equilateral Triangle</h3>
<ul>
<li>3 equal sides, 3 equal angles</li>
<li>Each interior angle = <strong>60°</strong></li>
<li>Turn angle (exterior) = 180° − 60° = <strong>120°</strong></li>
<li>3 × 120° = 360° ✓</li>
</ul>
<h3>Angle Sum Theorem</h3>
<p>For any triangle, the interior angles sum to <strong>180°</strong>. For an equilateral triangle: 60° + 60° + 60° = 180°. For a square: 90° + 90° + 90° + 90° = 360°.</p>
<blockquote><strong>📐 Maths tip.</strong> General formula: Sum of interior angles = (n − 2) × 180°, where n is the number of sides. Triangle: 1 × 180° = 180°. Square: 2 × 180° = 360°. Pentagon: 3 × 180° = 540°. Each extra side adds another 180° because you can cut the new polygon into one more triangle.</blockquote>
<blockquote><strong>🚶 Walk it out.</strong> At each corner of an equilateral triangle, you swivel through 120°. Three corners × 120° = 360° — the full turn you need to come back facing the way you started. On a square, four corners × 90° = 360°. Same total turn, just split into different sized swivels. This is the same "sum to 360°" rule from §02.</blockquote>
<blockquote><strong>💡 Coding tip.</strong> Notice we use <em>two</em> separate pen variables — <code>triangle</code> and <code>square</code> — one for each shape. You can have as many pens on the canvas as you like, and each one keeps its own position, heading, and colour. You'll explore this much more in Chapter II.</blockquote>
<div class="img-wrap">
<img src="images/06-triangle-in-square.png" alt="Triangle in a Square">
</div>
<button class="solution-toggle" onclick="toggleSolution(this,'sol-trisq')">
<svg width="12" height="7" viewBox="0 0 12 7" fill="none"><path d="M1 1l5 5 5-5" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/></svg>
Show Solution
</button>
<div class="solution-body" id="sol-trisq">
<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">triangle</span> = <span class="tp">Pen</span>()
<span class="vr">triangle</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">triangle</span>.<span class="fn">turn</span>(degrees: <span class="num">120</span>)
<span class="vr">triangle</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">triangle</span>.<span class="fn">turn</span>(degrees: <span class="num">120</span>)
<span class="vr">triangle</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="kw">var</span> <span class="vr">square</span> = <span class="tp">Pen</span>()
<span class="vr">square</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">square</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">square</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">square</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">square</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="vr">square</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">square</span>.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
<span class="fn">addShape</span>(pen: <span class="vr">triangle</span>)
<span class="fn">addShape</span>(pen: <span class="vr">square</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 angle sum</td><td>All triangles: angles sum to <strong>180°</strong>; equilateral = 3 × 60°</td></tr>
<tr><td>Interior angle formula</td><td>(n−2) × 180° / n: triangle → 60°; square → 90°</td></tr>
<tr><td>Polygon comparison</td><td>Different n-gons need different turn angles to close their paths</td></tr>
</table>
</div>
</div>
</section>
<!-- ═══════════════════════════════════════════════════════
07 — UP AND DOWN
═══════════════════════════════════════════════════════ -->
<section id="up-and-down">
<div class="section-hero">
<span class="section-tag tutorial">◆ Tutorial</span>
<h1>Up and Down</h1>
<p class="lead">Meet <code>move(distance:)</code> — just like <code>addLine</code>, but without drawing. Use it to reposition the pen and draw shapes in separate locations.</p>
<button class="complete-btn" data-id="up-and-down" onclick="toggleComplete(this)">
<span class="btn-icon">○</span> Mark as Complete
</button>
</div>
<div class="article">
<h2>Moving Without Drawing</h2>
<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">addLine</span>(distance: <span class="num">100</span>) <span class="cm">// Moves forward AND draws a line</span>
<span class="vr">p</span>.<span class="fn">move</span>(distance: <span class="num">100</span>) <span class="cm">// Moves forward — no line drawn</span></pre>
</div>
<p>The two commands behave identically in terms of changing the pen's position — the only difference is whether a line appears on screen.</p>
<blockquote><strong>💡 Coding tip.</strong> Think of <code>addLine</code> as "pen down and step forward"; think of <code>move</code> as "pen up and step forward". Same step, different state. Every classical pen-graphics system has these same two commands — they're what let you separate <em>where I go</em> from <em>what I draw</em>.</blockquote>
<h3>Dashed Lines</h3>
<p>Alternating <code>addLine</code> and <code>move</code> creates a <strong>dashed line</strong>:</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">addLine</span>(distance: <span class="num">50</span>) <span class="cm">// dash</span>
<span class="vr">p</span>.<span class="fn">move</span>(distance: <span class="num">20</span>) <span class="cm">// gap</span>
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">50</span>) <span class="cm">// dash</span>
<span class="vr">p</span>.<span class="fn">move</span>(distance: <span class="num">20</span>) <span class="cm">// gap</span>
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">50</span>) <span class="cm">// dash</span>
<span class="fn">addShape</span>(pen: <span class="vr">p</span>)</pre>
</div>
<h3>Exercise: Two Stacked Squares</h3>
<p>Try drawing two separate squares — one above the other — using a single pen. Use <code>move</code> to jump from the first square to the second without connecting them.</p>
<blockquote><strong>📐 Maths tip.</strong> Moving the pen without drawing is a <strong>translation</strong> — it slides the pen's position without rotating or resizing anything. The second square you draw is a translated copy of the first: every point is shifted by the same amount in the same direction. That's the formal definition of a translation, and you'll meet it again in Chapter V.</blockquote>
<div class="img-wrap">
<img src="images/07-up-and-down.png" alt="Two squares next to each other">
</div>
<button class="solution-toggle" onclick="toggleSolution(this,'sol-updown')">
<svg width="12" height="7" viewBox="0 0 12 7" fill="none"><path d="M1 1l5 5 5-5" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/></svg>
Show Solution
</button>
<div class="solution-body" id="sol-updown">
<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">// First square</span>
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">80</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">80</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">80</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">80</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="cm">// Jump up to next position</span>
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>) <span class="cm">// Face upward</span>
<span class="vr">p</span>.<span class="fn">move</span>(distance: <span class="num">120</span>) <span class="cm">// Move up 120 units</span>
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: -<span class="num">90</span>) <span class="cm">// Face right again</span>
<span class="cm">// Second square</span>
<span class="vr">p</span>.<span class="fn">addLine</span>(distance: <span class="num">80</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">80</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">80</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">80</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>Transformations — translations</td><td><code>move(distance:)</code> is a <strong>translation</strong> — the pen slides without rotating</td></tr>
<tr><td>Congruence</td><td>Two squares drawn at different positions are <strong>congruent</strong> — identical in size, shape, and angles</td></tr>
<tr><td>Coordinate geometry</td><td>Moving up increases y; moving right increases x</td></tr>
</table>
</div>
</div>
</section>
<!-- ═══════════════════════════════════════════════════════
08 — MULTIPLE SHAPES
═══════════════════════════════════════════════════════ -->
<section id="multiple-shapes">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>Multiple Shapes</h1>
<p class="lead">Draw three shapes in a horizontal row: a square, a triangle, and another square — each with side length 100. Use <code>move</code> to leave a gap between them.</p>
<button class="complete-btn" data-id="multiple-shapes" onclick="toggleComplete(this)">
<span class="btn-icon">○</span> Mark as Complete
</button>
</div>
<div class="article">
<h2>Your Task</h2>
<p>Using one or more pens, draw a square (100), an equilateral triangle (100), and another square (100) in a row with small gaps between each shape.</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 1, then move, then Triangle, then move, then Square 2</span>
<span class="fn">addShape</span>(pen: <span class="vr">p</span>)</pre>
</div>
<h2>Mathematical Concepts</h2>
<h3>Composing Shapes</h3>
<p>Placing shapes side-by-side is an example of <strong>geometric composition</strong> — building complex figures from simple ones. The second square is a <strong>translation</strong> of the first — same shape, moved horizontally.</p>
<blockquote><strong>📐 Maths tip.</strong> After drawing the triangle with three 120° turns, the pen's heading has changed by 360° — which means it ends up facing exactly where it started. That's not a coincidence — it's the "sum of exterior angles = 360°" rule from §02 doing its job. That's why the <code>move</code> after the triangle carries you horizontally without any extra turning.</blockquote>
<blockquote><strong>💡 Coding tip.</strong> One pen can draw as many shapes as you like, one after another. Chapter VI is entirely about composing small shapes — squares, triangles, circles — into bigger scenes like a house, a tree, or a whole suburban street.</blockquote>
<div class="img-wrap">
<img src="images/08-multiple-shapes.png" alt="Triangle with two squares either side">
</div>
<button class="solution-toggle" onclick="toggleSolution(this,'sol-multi')">
<svg width="12" height="7" viewBox="0 0 12 7" fill="none"><path d="M1 1l5 5 5-5" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/></svg>
Show Solution
</button>
<div class="solution-body" id="sol-multi">
<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 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">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">// Gap to triangle</span>
<span class="vr">p</span>.<span class="fn">move</span>(distance: <span class="num">120</span>)
<span class="cm">// Triangle</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">120</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">120</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">120</span>)
<span class="cm">// Gap to square 2 (pen already faces right after 3 × 120° = 360°)</span>
<span class="vr">p</span>.<span class="fn">move</span>(distance: <span class="num">120</span>)
<span class="cm">// Square 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">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>Transformations — translations</td><td>Moving between shapes is a <strong>translation</strong>; the second square is the first translated</td></tr>
<tr><td>Congruence</td><td>The two squares are <strong>congruent</strong> — identical shape, size, and angles</td></tr>
<tr><td>Geometric modeling</td><td>Composing multiple shapes into one figure is a fundamental geometric skill</td></tr>
</table>
</div>
</div>
</section>
<!-- ═══════════════════════════════════════════════════════
09 — FIVE-POINT STAR
═══════════════════════════════════════════════════════ -->
<section id="five-point-star">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>Five-Point Star</h1>
<p class="lead">Draw a five-pointed star (pentagram) in a single continuous path. The secret lies in the turn angle: <strong>144°</strong>.</p>
<button class="complete-btn" data-id="five-point-star" onclick="toggleComplete(this)">
<span class="btn-icon">○</span> Mark as Complete
</button>
</div>
<div class="article">
<h2>Your Task</h2>
<p>Draw a five-pointed star. All arms should be the same length (150 units). The pen draws the whole star in one continuous stroke without lifting.</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">// 5 lines, 5 turns — what's the turn angle?</span>
<span class="fn">addShape</span>(pen: <span class="vr">p</span>)</pre>
</div>
<h2>Mathematical Concepts</h2>
<h3>The Turn Angle for a Pentagram</h3>
<p>For a regular polygon, the exterior angle = 360° / n. But for a <strong>star polygon</strong>, the path winds around the centre more than once.</p>
<ul>
<li>A pentagram winds around the centre <strong>twice</strong></li>
<li>Total rotation = 2 × 360° = <strong>720°</strong></li>
<li>Each of the 5 turns = 720° ÷ 5 = <strong>144°</strong></li>
</ul>
<blockquote><strong>📐 Maths tip — why 720°?</strong> A regular polygon path winds once (360°). A star polygon {5/2} winds twice — the path overlaps itself, completing two full loops before coming back to its start. Total turn = 2 × 360° = 720°. Spread that across 5 corners and each turn is 144°.</blockquote>
<blockquote><strong>🚶 Walk it out.</strong> Imagine walking along a pentagram. At each point you turn quite sharply — 144° is more than a right angle. Between the five points, you swivel through a total of 720°, which means you finish pointing the same way you started, just like on every other closed polygon. The difference is you spun around <em>twice</em>, not once.</blockquote>
<h3>Star Polygon Notation</h3>
<p>Mathematicians write this as <strong>{5/2}</strong> — a 5-point star connecting every 2nd vertex. The general turn angle for <strong>{n/k}</strong> is <strong>360k / n</strong>. For {5/2}: 360 × 2 / 5 = 144° ✓. You'll meet this formula again in Chapter III when you draw stars with a loop.</p>
<div class="img-wrap">
<img src="images/09-five-point-star.png" alt="Five point star">
</div>
<button class="solution-toggle" onclick="toggleSolution(this,'sol-star5')">
<svg width="12" height="7" viewBox="0 0 12 7" fill="none"><path d="M1 1l5 5 5-5" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/></svg>
Show Solution
</button>
<div class="solution-body" id="sol-star5">
<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">addLine</span>(distance: <span class="num">150</span>)
<span class="vr">p</span>.<span class="fn">turn</span>(degrees: <span class="num">144</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">144</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">144</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">144</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">144</span>)
<span class="fn">addShape</span>(pen: <span class="vr">p</span>)
<span class="cm">// 5 × 144° = 720° = 2 × 360° ✓</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>Angle relationships</td><td>Each star point is an <strong>acute</strong> angle (36°); the turn angle (144°) is obtuse</td></tr>
<tr><td>Sum of exterior angles</td><td>5 × 144° = 720° = 2 × 360° — the path winds <strong>twice</strong> around the centre</td></tr>
<tr><td>Star polygon {5/2}</td><td>A generalisation of the regular polygon concept — connecting every k-th vertex</td></tr>
</table>
</div>
</div>
</section>
<!-- ═══════════════════════════════════════════════════════
10 — STAR OF DAVID
═══════════════════════════════════════════════════════ -->
<section id="star-of-david">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>Star of David</h1>
<p class="lead">Draw a Star of David (hexagram) using two overlapping equilateral triangles — one pointing up, one pointing down.</p>
<button class="complete-btn" data-id="star-of-david" onclick="toggleComplete(this)">
<span class="btn-icon">○</span> Mark as Complete
</button>
</div>
<div class="article">
<h2>Your Task</h2>
<p>Draw a Star of David using two equilateral triangles of side length 150. The triangles should overlap to form a six-pointed star.</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">david</span> = <span class="tp">Pen</span>()
<span class="cm">// Triangle 1 — upward triangle (3 sides, 120° turns)</span>
<span class="cm">// Reposition to the start of triangle 2 without drawing.</span>
<span class="cm">// Use david.move(distance:) and david.turn(degrees:) to</span>
<span class="cm">// walk the pen to the top-right corner of triangle 2.</span>
<span class="cm">// Triangle 2 — downward triangle (3 sides, 120° turns)</span>
<span class="fn">addShape</span>(pen: <span class="vr">david</span>)</pre>
</div>
<h2>Mathematical Concepts</h2>
<h3>The Hexagram</h3>