-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path01.html
More file actions
1158 lines (1034 loc) · 69.3 KB
/
01.html
File metadata and controls
1158 lines (1034 loc) · 69.3 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>Getting Started — Geometry Playground</title>
<!-- SEO -->
<meta name="description" content="Chapter 1 of Geometry Playground: learn the Pen API, draw shapes using coordinates, and explore angles and basic geometry with Swift Playgrounds on iPad or Mac." />
<meta name="keywords" content="Swift Playgrounds, getting started, coordinate geometry, Pen API, drawing shapes, angles, Swift for beginners, iPad coding, geometry chapter 1" />
<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="Getting Started — Geometry Playground" />
<meta property="og:description" content="Chapter 1: learn the Pen API, draw shapes using coordinates, and explore angles and basic geometry with Swift Playgrounds 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="Getting Started — Geometry Playground" />
<meta name="twitter:description" content="Chapter 1: learn the Pen API, draw shapes using coordinates, and explore angles and basic geometry with Swift Playgrounds 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": "Getting Started — Geometry Playground Chapter 1",
"description": "Learn the Pen API, draw shapes using coordinates, and explore angles and basic geometry concepts 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"
}
</script>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<!-- ══════════════════════════════════════════════════════════
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>
Ch 1 — Getting Started
<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">01</span> Getting Started</a>
<a href="02.html"><span class="dd-num">02</span> Fancy Shapes</a>
<a href="03.html"><span class="dd-num">03</span> Doing Stuff Again</a>
<a href="04.html"><span class="dd-num">04</span> Testing & Classifying</a>
<a href="05.html"><span class="dd-num">05</span> Tell It How</a>
<a href="06.html"><span class="dd-num">06</span> Suburban Scene</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 1</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 1</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 1 of 6</div>
<h1>Getting Started</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. You'll draw squares, triangles, stars and more — building your geometric intuition 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. Think of it like a turtle on a canvas — it has a position and a direction, and it moves forward when you tell it to.</p>
<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> (left turn).</p>
<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">IM1 Curriculum Connections</div>
<table>
<tr><th>IM1 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. Positive degrees turn <strong>left</strong> (anti-clockwise); negative degrees turn <strong>right</strong> (clockwise).</p>
<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>
<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">IM1 Curriculum Connections</div>
<table>
<tr><th>IM1 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>
<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">IM1 Curriculum Connections</div>
<table>
<tr><th>IM1 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>
<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">IM1 Curriculum Connections</div>
<table>
<tr><th>IM1 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>
<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">IM1 Curriculum Connections</div>
<table>
<tr><th>IM1 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>General formula: Sum of interior angles = (n − 2) × 180°, where n is the number of sides.</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">IM1 Curriculum Connections</div>
<table>
<tr><th>IM1 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>
<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>
<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">IM1 Curriculum Connections</div>
<table>
<tr><th>IM1 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>
<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">IM1 Curriculum Connections</div>
<table>
<tr><th>IM1 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>Why 720°?</strong> A regular polygon path winds once (360°). A star polygon {5/2} winds twice — the path overlaps itself, completing two loops before returning to the start.</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 {n/k} is: 180° − 180°(n−2k)/n.</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">IM1 Curriculum Connections</div>
<table>
<tr><th>IM1 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">up</span> = <span class="tp">Pen</span>()
<span class="cm">// Draw upward triangle</span>
<span class="kw">var</span> <span class="vr">down</span> = <span class="tp">Pen</span>()
<span class="cm">// Draw downward triangle</span>
<span class="fn">addShape</span>(pen: <span class="vr">up</span>)
<span class="fn">addShape</span>(pen: <span class="vr">down</span>)</pre>
</div>
<h2>Mathematical Concepts</h2>
<h3>The Hexagram</h3>
<p>Unlike the five-pointed star (drawn in one continuous path), a hexagram is formed from <strong>two separate triangles</strong>. The downward triangle is a <strong>rotation</strong> of the upward triangle by 60° around the centre.</p>
<h3>Rotational Symmetry</h3>
<p>A shape has <strong>rotational symmetry</strong> if it can be rotated by less than 360° and look identical. The Star of David has <strong>order-6</strong> rotational symmetry — it looks the same after rotations of 60°, 120°, 180°, 240°, or 300°.</p>
<ul>
<li>Square → order-4 symmetry (looks same after 90°, 180°, 270°)</li>
<li>Equilateral triangle → order-3 symmetry (looks same after 120°, 240°)</li>
<li>Star of David → <strong>order-6</strong> symmetry</li>
</ul>
<div class="img-wrap">
<img src="images/10-star-of-david.png" alt="Star of David">
</div>
<button class="solution-toggle" onclick="toggleSolution(this,'sol-david')">
<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-david">
<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</span>
<span class="vr">david</span>.<span class="fn">addLine</span>(distance: <span class="num">150</span>)
<span class="vr">david</span>.<span class="fn">turn</span>(degrees: <span class="num">120</span>)
<span class="vr">david</span>.<span class="fn">addLine</span>(distance: <span class="num">150</span>)
<span class="vr">david</span>.<span class="fn">turn</span>(degrees: <span class="num">120</span>)
<span class="vr">david</span>.<span class="fn">addLine</span>(distance: <span class="num">150</span>)
<span class="vr">david</span>.<span class="fn">turn</span>(degrees: <span class="num">120</span>)
<span class="cm">// New start point</span>
<span class="vr">david</span>.<span class="fn">move</span>(distance: <span class="num">150</span>)
<span class="vr">david</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">david</span>.<span class="fn">move</span>(distance: <span class="num">90</span>)
<span class="vr">david</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="cm">// Triangle 2</span>
<span class="vr">david</span>.<span class="fn">addLine</span>(distance: <span class="num">150</span>)
<span class="vr">david</span>.<span class="fn">turn</span>(degrees: <span class="num">120</span>)
<span class="vr">david</span>.<span class="fn">addLine</span>(distance: <span class="num">150</span>)
<span class="vr">david</span>.<span class="fn">turn</span>(degrees: <span class="num">120</span>)
<span class="vr">david</span>.<span class="fn">addLine</span>(distance: <span class="num">150</span>)
<span class="vr">david</span>.<span class="fn">turn</span>(degrees: <span class="num">120</span>)
<span class="fn">addShape</span>(pen: <span class="vr">david</span>)</pre>
</div>
</div>
<div class="callout">
<h3>💡 Think About It</h3>
<ul>
<li>How does the Star of David differ from the five-pointed star?</li>
<li>Can you see the regular hexagon hidden in the middle?</li>
<li>What other shapes can be constructed by overlapping simpler shapes?</li>
</ul>
</div>
<div class="im-table-wrap">
<div class="im-table-header">IM1 Curriculum Connections</div>
<table>
<tr><th>IM1 Concept</th><th>Connection</th></tr>
<tr><td>Transformations — rotations</td><td>The downward triangle is a <strong>rotation</strong> of the upward triangle by 60° around the centre</td></tr>
<tr><td>Congruence</td><td>The two triangles are <strong>congruent</strong> — same size, same angles; one is a rigid transformation of the other</td></tr>
<tr><td>Rotational symmetry</td><td>The hexagram has <strong>order-6</strong> rotational symmetry</td></tr>
<tr><td>Triangle properties</td><td>Both triangles are equilateral: 3 equal sides, 3 × 60° interior angles</td></tr>
</table>
</div>
</div>
</section>
<footer class="chapter-footer">
<a href="02.html" class="btn-next-chapter">Next Chapter <span class="next-arrow">→</span></a>
</footer>
</main>
</div><!-- /.layout -->
<script>
/* ═══════════════════════════════════════════════════════════════
PROGRESS SYSTEM (localStorage)
═══════════════════════════════════════════════════════════════ */
const STORAGE_KEY = 'gp_ch1_progress';
const EXERCISE_IDS = [
'intro-to-pen','turning-corners','squares','rectangles',
'more-squares','triangle-in-square','up-and-down',
'multiple-shapes','five-point-star','star-of-david'
];
// Only count exercises (not tutorials) for "X done"
const COUNTABLE = [
'squares','rectangles','more-squares','triangle-in-square',
'multiple-shapes','five-point-star','star-of-david','up-and-down'
];
function loadProgress() {
try { return JSON.parse(localStorage.getItem(STORAGE_KEY)) || {}; }
catch(e) { return {}; }
}
function saveProgress(data) {
try { localStorage.setItem(STORAGE_KEY, JSON.stringify(data)); }
catch(e) {}
}
function applyProgress() {
const data = loadProgress();
EXERCISE_IDS.forEach(id => {
if (data[id]) {
markDone(id, false);
}
});
updateProgressBar();
}
function markDone(id, save) {