-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path05.html
More file actions
1352 lines (1270 loc) · 83.3 KB
/
05.html
File metadata and controls
1352 lines (1270 loc) · 83.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>Tell It How — Geometry Playground</title>
<!-- SEO -->
<meta name="description" content="Chapter 5 of Geometry Playground: define functions with parameters to draw reusable shapes, explore similarity and scale, and build geometric transformations with Swift Playgrounds." />
<meta name="keywords" content="Swift Playgrounds, functions, parameters, geometric transformations, similarity, scale, reusable shapes, Swift programming, geometry chapter 5, dilation" />
<meta name="author" content="Daniel Budd" />
<meta name="robots" content="index, follow" />
<link rel="canonical" href="https://dbbudd.github.io/05.html" />
<!-- Open Graph -->
<meta property="og:type" content="article" />
<meta property="og:site_name" content="Geometry Playground" />
<meta property="og:title" content="Tell It How — Geometry Playground" />
<meta property="og:description" content="Chapter 5: define functions with parameters to draw reusable shapes, explore similarity and scale, and build geometric transformations with Swift Playgrounds." />
<meta property="og:url" content="https://dbbudd.github.io/05.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="Tell It How — Geometry Playground" />
<meta name="twitter:description" content="Chapter 5: define functions with parameters to draw reusable shapes, explore similarity and scale, and build geometric transformations with Swift Playgrounds." />
<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": "Tell It How — Geometry Playground Chapter 5",
"description": "Define functions with parameters to draw reusable shapes, explore similarity and scale, and build geometric transformations with Swift Playgrounds on iPad or Mac.",
"url": "https://dbbudd.github.io/05.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": "Functions, Parameters, Similarity, Geometric Transformations, Scale, Dilation, Reusable Code"
}
</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>
05 — Tell It How
<svg width="10" height="6" viewBox="0 0 10 6" fill="none"><path d="M1 1l4 4 4-4" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg>
</button>
<div class="nav-dropdown">
<div class="nav-dropdown-heading">Chapters</div>
<a href="01.html"><span class="dd-num">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" class="active"><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="currentSectionLabel">01 — Creating Functions</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">
<div class="nav-dropdown-heading">Sections</div>
<a href="#s01" class="active"><span class="nav-num">01</span><span>Creating Functions<br><span class="nav-badge badge-tutorial">Tutorial</span></span><span class="nav-done">✓</span></a>
<a href="#s02"><span class="nav-num">02</span><span>Octagons<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s03"><span class="nav-num">03</span><span>Parameters<br><span class="nav-badge badge-tutorial">Tutorial</span></span><span class="nav-done">✓</span></a>
<a href="#s04"><span class="nav-num">04</span><span>Different Sizes<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s05"><span class="nav-num">05</span><span>Different Shapes<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<hr class="dd-sep"/>
<a href="#s06"><span class="nav-num">06</span><span>Denmark<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s07"><span class="nav-num">07</span><span>Sweden<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s08"><span class="nav-num">08</span><span>Norway<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s09"><span class="nav-num">09</span><span>St Andrew<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s10"><span class="nav-num">10</span><span>St Patrick<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s11"><span class="nav-num">11</span><span>St George<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s12"><span class="nav-num">12</span><span>Union Jack<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s13"><span class="nav-num">13</span><span>Filled Star<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s14"><span class="nav-num">14</span><span>Australia<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s15"><span class="nav-num">15</span><span>Netherlands<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s16"><span class="nav-num">16</span><span>France<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s17"><span class="nav-num">17</span><span>Positions<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s18"><span class="nav-num">18</span><span>Switzerland<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s19"><span class="nav-num">19</span><span>Tonga<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s20"><span class="nav-num">20</span><span>Puerto Rico<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s21"><span class="nav-num">21</span><span>United States<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
</div>
</div>
<!-- Chapter progress -->
<div class="topbar-progress">
<span class="progress-text" id="progressText">0 / 19</span>
<div class="progress-bar-wrap">
<div class="progress-bar-fill" id="progressBarFill"></div>
</div>
</div>
</header>
<!-- ══════════════════════════════════════════════════════════
LAYOUT
══════════════════════════════════════════════════════════ -->
<div class="page-wrap">
<!-- ── SIDEBAR ── -->
<aside class="sidebar" id="sidebar">
<div class="sidebar-chapter">Chapter 05</div>
<nav id="sidebarNav">
<a href="#s01" class="active"><span class="nav-num">01</span><span>Creating Functions<br><span class="nav-badge badge-tutorial">Tutorial</span></span><span class="nav-done">✓</span></a>
<a href="#s02"><span class="nav-num">02</span><span>Octagons<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s03"><span class="nav-num">03</span><span>Parameters<br><span class="nav-badge badge-tutorial">Tutorial</span></span><span class="nav-done">✓</span></a>
<a href="#s04"><span class="nav-num">04</span><span>Different Sizes<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s05"><span class="nav-num">05</span><span>Different Shapes<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s06"><span class="nav-num">06</span><span>Denmark<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s07"><span class="nav-num">07</span><span>Sweden<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s08"><span class="nav-num">08</span><span>Norway<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s09"><span class="nav-num">09</span><span>St Andrew<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s10"><span class="nav-num">10</span><span>St Patrick<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s11"><span class="nav-num">11</span><span>St George<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s12"><span class="nav-num">12</span><span>Union Jack<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s13"><span class="nav-num">13</span><span>Filled Star<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s14"><span class="nav-num">14</span><span>Australia<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s15"><span class="nav-num">15</span><span>Netherlands<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s16"><span class="nav-num">16</span><span>France<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s17"><span class="nav-num">17</span><span>Positions<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s18"><span class="nav-num">18</span><span>Switzerland<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s19"><span class="nav-num">19</span><span>Tonga<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s20"><span class="nav-num">20</span><span>Puerto Rico<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
<a href="#s21"><span class="nav-num">21</span><span>United States<br><span class="nav-badge badge-exercise">Exercise</span></span><span class="nav-done">✓</span></a>
</nav>
</aside>
<!-- ── MAIN CONTENT ── -->
<main class="content" id="mainContent">
<!-- Chapter Banner -->
<section class="section-hero chapter-banner" id="chapter-top">
<div class="ch-label">Chapter 5 of 6</div>
<h1>Tell It How</h1>
<p class="lead">Write reusable functions with parameters to draw flags from around the world and complex geometric compositions.</p>
<div class="banner-meta">
<div class="banner-stat"><span class="stat-num">21</span><span class="stat-label">Sections</span></div>
<div class="banner-stat"><span class="stat-num">2</span><span class="stat-label">Tutorials</span></div>
<div class="banner-stat"><span class="stat-num">19</span><span class="stat-label">Exercises</span></div>
</div>
</section>
<!-- ════════════════════════════════════════
SECTION 01 — Creating Functions (Tutorial)
════════════════════════════════════════ -->
<section id="s01">
<div class="section-hero">
<span class="section-tag tutorial">◆ Tutorial</span>
<h1>Creating Functions</h1>
<p class="lead">A <strong>function</strong> is a named block of code you can call whenever you need it. Instead of copying the same loop every time you want a square, you define it once in a function.</p>
<button class="complete-btn" data-id="s01" onclick="toggleComplete(this)">
<span class="btn-icon">○</span> Mark as Complete
</button>
</div>
<div class="article">
<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">func</span> <span class="fn">drawSquare</span>() {
<span class="kw">for</span> _ <span class="kw">in</span> <span class="num">1</span>...<span class="num">4</span> {
pen.<span class="fn">addLine</span>(distance: <span class="num">100</span>)
pen.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
}
}
<span class="cm">// Call it as many times as you like:</span>
<span class="fn">drawSquare</span>()
pen.<span class="fn">move</span>(distance: <span class="num">120</span>)
<span class="fn">drawSquare</span>()</pre>
</div>
<p>Functions promote <strong>DRY code</strong> — Don't Repeat Yourself. If you need to change the square size, you only change it in one place.</p>
<div class="img-placeholder">
<span class="img-icon">📷</span>
<span class="img-name">05-01-creating-functions.png</span>
<span class="img-hint">Image coming soon</span>
</div>
<div class="im-table-wrap">
<div class="im-table-header">IM1 Curriculum Connection</div>
<table class="im-table">
<thead><tr><th>Standard</th><th>Connection</th></tr></thead>
<tbody>
<tr><td>Functions & Modelling</td><td>A function in programming is analogous to a function in mathematics: it encapsulates a process. Calling a function repeatedly mirrors evaluating f(x) for multiple inputs.</td></tr>
</tbody>
</table>
</div>
</div>
</section>
<!-- ════════════════════════════════════════
SECTION 02 — Octagons
════════════════════════════════════════ -->
<section id="s02">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>Octagons</h1>
<p class="lead">Write a function called <code>drawOctagon()</code> that draws a regular octagon (8 sides, exterior angle 45°). Call it three times to draw a row of three octagons.</p>
<button class="complete-btn" data-id="s02" onclick="toggleComplete(this)">
<span class="btn-icon">○</span> Mark as Complete
</button>
</div>
<div class="article">
<div class="img-placeholder">
<span class="img-icon">📷</span>
<span class="img-name">05-02-octagons.png</span>
<span class="img-hint">Image coming soon</span>
</div>
<button class="solution-toggle" onclick="toggleSolution(this,'sol02')">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
Show Solution
</button>
<div class="solution-body" id="sol02">
<div class="code-wrap">
<div class="code-header">
<span class="code-lang">Solution</span>
<button class="code-copy" onclick="copyCode(this)">Copy</button>
</div>
<pre><span class="kw">func</span> <span class="fn">drawOctagon</span>() {
<span class="kw">for</span> _ <span class="kw">in</span> <span class="num">1</span>...<span class="num">8</span> {
pen.<span class="fn">addLine</span>(distance: <span class="num">80</span>)
pen.<span class="fn">turn</span>(degrees: <span class="num">45</span>)
}
}
<span class="fn">drawOctagon</span>()
pen.<span class="fn">move</span>(distance: <span class="num">100</span>)
<span class="fn">drawOctagon</span>()
pen.<span class="fn">move</span>(distance: <span class="num">100</span>)
<span class="fn">drawOctagon</span>()</pre>
</div>
</div>
<div class="im-table-wrap">
<div class="im-table-header">IM1 Curriculum Connection</div>
<table class="im-table">
<thead><tr><th>Standard</th><th>Connection</th></tr></thead>
<tbody>
<tr><td>Geometry — Regular Polygons</td><td>A regular octagon has 8 sides and exterior angles of 360°/8 = 45°. Its interior angles are 180° − 45° = 135°.</td></tr>
</tbody>
</table>
</div>
</div>
</section>
<!-- ════════════════════════════════════════
SECTION 03 — Parameters (Tutorial)
════════════════════════════════════════ -->
<section id="s03">
<div class="section-hero">
<span class="section-tag tutorial">◆ Tutorial</span>
<h1>Parameters</h1>
<p class="lead">Functions become far more powerful when they accept <strong>parameters</strong> — values passed in by the caller. The function uses the parameter name like a variable inside its body.</p>
<button class="complete-btn" data-id="s03" onclick="toggleComplete(this)">
<span class="btn-icon">○</span> Mark as Complete
</button>
</div>
<div class="article">
<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">func</span> <span class="fn">drawSquare</span>(size: <span class="tp">Double</span>) {
<span class="kw">for</span> _ <span class="kw">in</span> <span class="num">1</span>...<span class="num">4</span> {
pen.<span class="fn">addLine</span>(distance: <span class="vr">size</span>)
pen.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
}
}
<span class="cm">// Draw squares of different sizes:</span>
<span class="fn">drawSquare</span>(size: <span class="num">50</span>)
<span class="fn">drawSquare</span>(size: <span class="num">100</span>)
<span class="fn">drawSquare</span>(size: <span class="num">150</span>)</pre>
</div>
<p>You can have multiple parameters, separated by commas. Swift uses <strong>argument labels</strong> at the call site for readability:</p>
<div class="code-wrap">
<div class="code-header">
<span class="code-lang">Multiple parameters</span>
<button class="code-copy" onclick="copyCode(this)">Copy</button>
</div>
<pre><span class="kw">func</span> <span class="fn">drawRectangle</span>(width: <span class="tp">Double</span>, height: <span class="tp">Double</span>) {
<span class="kw">for</span> _ <span class="kw">in</span> <span class="num">1</span>...<span class="num">2</span> {
pen.<span class="fn">addLine</span>(distance: <span class="vr">width</span>)
pen.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
pen.<span class="fn">addLine</span>(distance: <span class="vr">height</span>)
pen.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
}
}
<span class="fn">drawRectangle</span>(width: <span class="num">200</span>, height: <span class="num">100</span>)</pre>
</div>
<div class="img-placeholder">
<span class="img-icon">📷</span>
<span class="img-name">05-03-parameters.png</span>
<span class="img-hint">Image coming soon</span>
</div>
<div class="im-table-wrap">
<div class="im-table-header">IM1 Curriculum Connection</div>
<table class="im-table">
<thead><tr><th>Standard</th><th>Connection</th></tr></thead>
<tbody>
<tr><td>Functions & Modelling</td><td>A parameterised function is a direct model of a mathematical function f(x). The parameter is the input, and the drawn shape is the output. Multiple parameters map to multi-variable functions f(x, y).</td></tr>
</tbody>
</table>
</div>
</div>
</section>
<!-- ════════════════════════════════════════
SECTION 04 — Different Sizes
════════════════════════════════════════ -->
<section id="s04">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>Different Sizes</h1>
<p class="lead">Write a function <code>drawRegularPolygon(sides: Int, sideLength: Double)</code> that draws any regular polygon. Use it to draw a triangle, square, pentagon, hexagon, and octagon, each a different size, arranged in a row.</p>
<button class="complete-btn" data-id="s04" onclick="toggleComplete(this)">
<span class="btn-icon">○</span> Mark as Complete
</button>
</div>
<div class="article">
<div class="img-placeholder">
<span class="img-icon">📷</span>
<span class="img-name">05-04-different-sizes.png</span>
<span class="img-hint">Image coming soon</span>
</div>
<button class="solution-toggle" onclick="toggleSolution(this,'sol04')">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
Show Solution
</button>
<div class="solution-body" id="sol04">
<div class="code-wrap">
<div class="code-header">
<span class="code-lang">Solution</span>
<button class="code-copy" onclick="copyCode(this)">Copy</button>
</div>
<pre><span class="kw">func</span> <span class="fn">drawRegularPolygon</span>(sides: <span class="tp">Int</span>, sideLength: <span class="tp">Double</span>) {
<span class="kw">let</span> <span class="vr">angle</span> = <span class="num">360.0</span> / <span class="tp">Double</span>(<span class="vr">sides</span>)
<span class="kw">for</span> _ <span class="kw">in</span> <span class="num">1</span>...<span class="vr">sides</span> {
pen.<span class="fn">addLine</span>(distance: <span class="vr">sideLength</span>)
pen.<span class="fn">turn</span>(degrees: <span class="vr">angle</span>)
}
}
<span class="fn">drawRegularPolygon</span>(sides: <span class="num">3</span>, sideLength: <span class="num">60</span>)
pen.<span class="fn">move</span>(distance: <span class="num">80</span>)
<span class="fn">drawRegularPolygon</span>(sides: <span class="num">4</span>, sideLength: <span class="num">60</span>)
pen.<span class="fn">move</span>(distance: <span class="num">80</span>)
<span class="fn">drawRegularPolygon</span>(sides: <span class="num">5</span>, sideLength: <span class="num">60</span>)
pen.<span class="fn">move</span>(distance: <span class="num">80</span>)
<span class="fn">drawRegularPolygon</span>(sides: <span class="num">6</span>, sideLength: <span class="num">60</span>)
pen.<span class="fn">move</span>(distance: <span class="num">80</span>)
<span class="fn">drawRegularPolygon</span>(sides: <span class="num">8</span>, sideLength: <span class="num">60</span>)</pre>
</div>
</div>
<div class="im-table-wrap">
<div class="im-table-header">IM1 Curriculum Connection</div>
<table class="im-table">
<thead><tr><th>Standard</th><th>Connection</th></tr></thead>
<tbody>
<tr><td>Geometry — Regular Polygons</td><td>A single parameterised function replaces six separate loop blocks. The exterior angle formula 360°/n shows a direct inverse relationship between number of sides and turn angle.</td></tr>
</tbody>
</table>
</div>
</div>
</section>
<!-- ════════════════════════════════════════
SECTION 05 — Different Shapes
════════════════════════════════════════ -->
<section id="s05">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>Different Shapes</h1>
<p class="lead">Write a function <code>drawRectangle(width: Double, height: Double, color: Color)</code> that draws a filled rectangle of any size and colour. Use it to create a colourful grid of rectangles — 3 columns, 3 rows, each a different colour and proportion.</p>
<button class="complete-btn" data-id="s05" onclick="toggleComplete(this)">
<span class="btn-icon">○</span> Mark as Complete
</button>
</div>
<div class="article">
<div class="img-placeholder">
<span class="img-icon">📷</span>
<span class="img-name">05-05-different-shapes.png</span>
<span class="img-hint">Image coming soon</span>
</div>
<button class="solution-toggle" onclick="toggleSolution(this,'sol05')">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
Show Solution
</button>
<div class="solution-body" id="sol05">
<div class="code-wrap">
<div class="code-header">
<span class="code-lang">Solution</span>
<button class="code-copy" onclick="copyCode(this)">Copy</button>
</div>
<pre><span class="kw">func</span> <span class="fn">drawRectangle</span>(width: <span class="tp">Double</span>, height: <span class="tp">Double</span>, color: <span class="tp">Color</span>) {
<span class="kw">let</span> <span class="vr">shape</span> = <span class="tp">Pen</span>()
<span class="vr">shape</span>.<span class="vr">fillColor</span> = <span class="vr">color</span>
<span class="kw">for</span> _ <span class="kw">in</span> <span class="num">1</span>...<span class="num">2</span> {
<span class="vr">shape</span>.<span class="fn">addLine</span>(distance: <span class="vr">width</span>)
<span class="vr">shape</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">shape</span>.<span class="fn">addLine</span>(distance: <span class="vr">height</span>)
<span class="vr">shape</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
}
pen.<span class="fn">addShape</span>(pen: <span class="vr">shape</span>)
}</pre>
</div>
</div>
<div class="im-table-wrap">
<div class="im-table-header">IM1 Curriculum Connection</div>
<table class="im-table">
<thead><tr><th>Standard</th><th>Connection</th></tr></thead>
<tbody>
<tr><td>Geometry — Area & Perimeter</td><td>Rectangles with the same perimeter can have different areas (and vice versa). Experimenting with width and height demonstrates this inverse relationship.</td></tr>
</tbody>
</table>
</div>
</div>
</section>
<!-- ════════════════════════════════════════
SECTION 06 — Denmark
════════════════════════════════════════ -->
<section id="s06">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>Denmark</h1>
<p class="lead">The Danish flag (Dannebrog) is a red rectangle with a white cross. The cross divides the flag into four rectangles. Write a function to draw the flag, with parameters for overall width and height.</p>
<button class="complete-btn" data-id="s06" onclick="toggleComplete(this)">
<span class="btn-icon">○</span> Mark as Complete
</button>
</div>
<div class="article">
<p><em>Traditional proportions: 28 × 21 units; cross bars are 4 units wide; vertical bar is offset left of centre.</em></p>
<div class="img-placeholder">
<span class="img-icon">📷</span>
<span class="img-name">05-06-denmark.png</span>
<span class="img-hint">Image coming soon</span>
</div>
<button class="solution-toggle" onclick="toggleSolution(this,'sol06')">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
Show Solution
</button>
<div class="solution-body" id="sol06">
<div class="code-wrap">
<div class="code-header">
<span class="code-lang">Solution</span>
<button class="code-copy" onclick="copyCode(this)">Copy</button>
</div>
<pre><span class="kw">func</span> <span class="fn">drawDenmark</span>(scale: <span class="tp">Double</span>) {
<span class="cm">// Red background</span>
<span class="kw">let</span> <span class="vr">bg</span> = <span class="tp">Pen</span>()
<span class="vr">bg</span>.<span class="vr">fillColor</span> = .<span class="vr">red</span>
<span class="kw">for</span> _ <span class="kw">in</span> <span class="num">1</span>...<span class="num">2</span> {
<span class="vr">bg</span>.<span class="fn">addLine</span>(distance: <span class="num">28</span> * <span class="vr">scale</span>)
<span class="vr">bg</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">bg</span>.<span class="fn">addLine</span>(distance: <span class="num">21</span> * <span class="vr">scale</span>)
<span class="vr">bg</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
}
pen.<span class="fn">addShape</span>(pen: <span class="vr">bg</span>)
<span class="cm">// White cross</span>
<span class="kw">let</span> <span class="vr">hBar</span> = <span class="tp">Pen</span>()
<span class="vr">hBar</span>.<span class="vr">fillColor</span> = .<span class="vr">white</span>
<span class="kw">for</span> _ <span class="kw">in</span> <span class="num">1</span>...<span class="num">2</span> {
<span class="vr">hBar</span>.<span class="fn">addLine</span>(distance: <span class="num">28</span> * <span class="vr">scale</span>)
<span class="vr">hBar</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="vr">hBar</span>.<span class="fn">addLine</span>(distance: <span class="num">4</span> * <span class="vr">scale</span>)
<span class="vr">hBar</span>.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
}
pen.<span class="fn">addShape</span>(pen: <span class="vr">hBar</span>)
}
<span class="fn">drawDenmark</span>(scale: <span class="num">5</span>)</pre>
</div>
</div>
<div class="im-table-wrap">
<div class="im-table-header">IM1 Curriculum Connection</div>
<table class="im-table">
<thead><tr><th>Standard</th><th>Connection</th></tr></thead>
<tbody>
<tr><td>Ratio & Proportion</td><td>Flag dimensions use fixed ratios (28:21 = 4:3). Scaling by a constant multiplier preserves proportions — an application of ratio and scale factor.</td></tr>
</tbody>
</table>
</div>
</div>
</section>
<!-- ════════════════════════════════════════
SECTIONS 07–16 — More Flags
════════════════════════════════════════ -->
<section id="s07">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>Sweden</h1>
<p class="lead">The Swedish flag is blue with a yellow Scandinavian cross (same offset proportions as Denmark but with a blue background and gold cross). Adapt your Denmark function to draw the Swedish flag.</p>
<button class="complete-btn" data-id="s07" onclick="toggleComplete(this)">
<span class="btn-icon">○</span> Mark as Complete
</button>
</div>
<div class="article">
<p><em>Proportions: 16 × 10 units; vertical bar 2 units wide at position 5 from left; horizontal bar 2 units wide at position 4 from top.</em></p>
<div class="img-placeholder">
<span class="img-icon">📷</span>
<span class="img-name">05-07-sweden.png</span>
<span class="img-hint">Image coming soon</span>
</div>
<button class="solution-toggle" onclick="toggleSolution(this,'sol07')">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
Show Solution
</button>
<div class="solution-body" id="sol07">
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Solution</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="kw">func</span> <span class="fn">drawSweden</span>(scale: <span class="tp">Double</span>) {
<span class="kw">let</span> <span class="vr">bg</span> = <span class="tp">Pen</span>(); <span class="vr">bg</span>.<span class="vr">fillColor</span> = .<span class="vr">blue</span>
<span class="kw">for</span> _ <span class="kw">in</span> <span class="num">1</span>...<span class="num">2</span> {
<span class="vr">bg</span>.<span class="fn">addLine</span>(distance: <span class="num">16</span>*<span class="vr">scale</span>); <span class="vr">bg</span>.<span class="fn">turn</span>(degrees:<span class="num">90</span>)
<span class="vr">bg</span>.<span class="fn">addLine</span>(distance: <span class="num">10</span>*<span class="vr">scale</span>); <span class="vr">bg</span>.<span class="fn">turn</span>(degrees:<span class="num">90</span>)
}
pen.<span class="fn">addShape</span>(pen: <span class="vr">bg</span>)
<span class="cm">// Yellow cross bars drawn at offsets</span>
<span class="kw">let</span> <span class="vr">cross</span> = <span class="tp">Pen</span>(); <span class="vr">cross</span>.<span class="vr">fillColor</span> = .<span class="vr">yellow</span>
<span class="kw">for</span> _ <span class="kw">in</span> <span class="num">1</span>...<span class="num">2</span> {
<span class="vr">cross</span>.<span class="fn">addLine</span>(distance: <span class="num">16</span>*<span class="vr">scale</span>); <span class="vr">cross</span>.<span class="fn">turn</span>(degrees:<span class="num">90</span>)
<span class="vr">cross</span>.<span class="fn">addLine</span>(distance: <span class="num">2</span>*<span class="vr">scale</span>); <span class="vr">cross</span>.<span class="fn">turn</span>(degrees:<span class="num">90</span>)
}
pen.<span class="fn">addShape</span>(pen: <span class="vr">cross</span>)
}
<span class="fn">drawSweden</span>(scale: <span class="num">8</span>)</pre>
</div>
</div>
<div class="im-table-wrap">
<div class="im-table-header">IM1 Curriculum Connection</div>
<table class="im-table">
<thead><tr><th>Standard</th><th>Connection</th></tr></thead>
<tbody><tr><td>Ratio & Proportion</td><td>Identifying how Denmark and Sweden share a cross design but with different proportions reinforces the concept of scaled geometric similarity.</td></tr></tbody>
</table>
</div>
</div>
</section>
<section id="s08">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>Norway</h1>
<p class="lead">Norway's flag has a red background with a blue cross outlined in white. Build on your Scandinavian cross function to add a second, slightly wider white cross drawn underneath the blue one.</p>
<button class="complete-btn" data-id="s08" onclick="toggleComplete(this)">
<span class="btn-icon">○</span> Mark as Complete
</button>
</div>
<div class="article">
<div class="img-placeholder">
<span class="img-icon">📷</span>
<span class="img-name">05-08-norway.png</span>
<span class="img-hint">Image coming soon</span>
</div>
<button class="solution-toggle" onclick="toggleSolution(this,'sol08')">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
Show Solution
</button>
<div class="solution-body" id="sol08">
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Hint</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="cm">// Draw layers: red bg → white cross (wider) → blue cross (narrower)</span>
<span class="cm">// Use pen.move() with negative distances to reposition between layers</span>
<span class="kw">func</span> <span class="fn">drawCrossBar</span>(width: <span class="tp">Double</span>, thickness: <span class="tp">Double</span>, color: <span class="tp">Color</span>) {
<span class="kw">let</span> <span class="vr">bar</span> = <span class="tp">Pen</span>(); <span class="vr">bar</span>.<span class="vr">fillColor</span> = <span class="vr">color</span>
<span class="kw">for</span> _ <span class="kw">in</span> <span class="num">1</span>...<span class="num">2</span> {
<span class="vr">bar</span>.<span class="fn">addLine</span>(distance: <span class="vr">width</span>); <span class="vr">bar</span>.<span class="fn">turn</span>(degrees:<span class="num">90</span>)
<span class="vr">bar</span>.<span class="fn">addLine</span>(distance: <span class="vr">thickness</span>); <span class="vr">bar</span>.<span class="fn">turn</span>(degrees:<span class="num">90</span>)
}
pen.<span class="fn">addShape</span>(pen: <span class="vr">bar</span>)
}</pre>
</div>
</div>
<div class="im-table-wrap">
<div class="im-table-header">IM1 Curriculum Connection</div>
<table class="im-table">
<thead><tr><th>Standard</th><th>Connection</th></tr></thead>
<tbody><tr><td>Geometry — Concentric Shapes</td><td>Drawing a white cross wider than the blue cross creates an outline via layering — analogous to the concept of border width as the difference between outer and inner dimensions.</td></tr></tbody>
</table>
</div>
</div>
</section>
<section id="s09">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>St Andrew</h1>
<p class="lead">The flag of Scotland features a white diagonal cross (saltire) on a blue background. Draw two diagonal lines connecting opposite corners of the flag's rectangle.</p>
<button class="complete-btn" data-id="s09" onclick="toggleComplete(this)">
<span class="btn-icon">○</span> Mark as Complete
</button>
</div>
<div class="article">
<p><em>Hint: use trigonometry (or Pythagoras) to calculate the diagonal length from the width and height.</em></p>
<div class="img-placeholder">
<span class="img-icon">📷</span>
<span class="img-name">05-09-st-andrew.png</span>
<span class="img-hint">Image coming soon</span>
</div>
<button class="solution-toggle" onclick="toggleSolution(this,'sol09')">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
Show Solution
</button>
<div class="solution-body" id="sol09">
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Solution</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="kw">import</span> Foundation
<span class="kw">let</span> <span class="vr">w</span>: <span class="tp">Double</span> = <span class="num">200</span>, <span class="vr">h</span>: <span class="tp">Double</span> = <span class="num">120</span>
<span class="kw">let</span> <span class="vr">diag</span> = <span class="fn">sqrt</span>(<span class="vr">w</span>*<span class="vr">w</span> + <span class="vr">h</span>*<span class="vr">h</span>)
<span class="kw">let</span> <span class="vr">angle</span> = <span class="fn">atan2</span>(<span class="vr">h</span>, <span class="vr">w</span>) * <span class="num">180</span> / .pi
<span class="cm">// Diagonal 1: bottom-left to top-right</span>
pen.<span class="fn">addLine</span>(distance: <span class="vr">diag</span>)
pen.<span class="fn">move</span>(distance: -<span class="vr">diag</span>)
<span class="cm">// Diagonal 2: top-left to bottom-right</span>
pen.<span class="fn">turn</span>(degrees: -<span class="vr">angle</span> * <span class="num">2</span>)
pen.<span class="fn">addLine</span>(distance: <span class="vr">diag</span>)</pre>
</div>
</div>
<div class="im-table-wrap">
<div class="im-table-header">IM1 Curriculum Connection</div>
<table class="im-table">
<thead><tr><th>Standard</th><th>Connection</th></tr></thead>
<tbody><tr><td>Pythagoras' Theorem</td><td>The diagonal of a rectangle with width w and height h has length √(w² + h²). This is a direct application of Pythagoras' theorem.</td></tr></tbody>
</table>
</div>
</div>
</section>
<section id="s10">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>St Patrick</h1>
<p class="lead">The St Patrick's Cross is a red diagonal saltire (like St Andrew's but red on white). Draw it using the same approach as St Andrew, but with a red diagonal and white background.</p>
<button class="complete-btn" data-id="s10" onclick="toggleComplete(this)">
<span class="btn-icon">○</span> Mark as Complete
</button>
</div>
<div class="article">
<div class="img-placeholder">
<span class="img-icon">📷</span>
<span class="img-name">05-10-st-patrick.png</span>
<span class="img-hint">Image coming soon</span>
</div>
<button class="solution-toggle" onclick="toggleSolution(this,'sol10')">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
Show Solution
</button>
<div class="solution-body" id="sol10">
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Hint</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="cm">// Reuse the St Andrew approach:</span>
<span class="cm">// 1. Draw white background rectangle</span>
<span class="cm">// 2. Set pen colour to red</span>
<span class="cm">// 3. Draw diagonals using sqrt(w²+h²)</span></pre>
</div>
</div>
<div class="im-table-wrap">
<div class="im-table-header">IM1 Curriculum Connection</div>
<table class="im-table">
<thead><tr><th>Standard</th><th>Connection</th></tr></thead>
<tbody><tr><td>Geometry — Similarity</td><td>St Patrick's Cross is geometrically identical to St Andrew's — the same shape, different colours. This demonstrates that geometric properties are independent of colour.</td></tr></tbody>
</table>
</div>
</div>
</section>
<section id="s11">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>St George</h1>
<p class="lead">England's flag is a white background with a red cross (like Denmark but centred). Use your Scandinavian cross function with centred proportions.</p>
<button class="complete-btn" data-id="s11" onclick="toggleComplete(this)">
<span class="btn-icon">○</span> Mark as Complete
</button>
</div>
<div class="article">
<div class="img-placeholder">
<span class="img-icon">📷</span>
<span class="img-name">05-11-st-george.png</span>
<span class="img-hint">Image coming soon</span>
</div>
<button class="solution-toggle" onclick="toggleSolution(this,'sol11')">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
Show Solution
</button>
<div class="solution-body" id="sol11">
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Solution</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="kw">func</span> <span class="fn">drawStGeorge</span>(scale: <span class="tp">Double</span>) {
<span class="cm">// White background 3:2 proportions</span>
<span class="kw">let</span> <span class="vr">bg</span> = <span class="tp">Pen</span>(); <span class="vr">bg</span>.<span class="vr">fillColor</span> = .<span class="vr">white</span>
<span class="kw">for</span> _ <span class="kw">in</span> <span class="num">1</span>...<span class="num">2</span> {
<span class="vr">bg</span>.<span class="fn">addLine</span>(distance:<span class="num">30</span>*<span class="vr">scale</span>); <span class="vr">bg</span>.<span class="fn">turn</span>(degrees:<span class="num">90</span>)
<span class="vr">bg</span>.<span class="fn">addLine</span>(distance:<span class="num">20</span>*<span class="vr">scale</span>); <span class="vr">bg</span>.<span class="fn">turn</span>(degrees:<span class="num">90</span>)
}
pen.<span class="fn">addShape</span>(pen: <span class="vr">bg</span>)
<span class="cm">// Red centred cross — horizontal and vertical bars</span>
<span class="kw">let</span> <span class="vr">hBar</span> = <span class="tp">Pen</span>(); <span class="vr">hBar</span>.<span class="vr">fillColor</span> = .<span class="vr">red</span>
<span class="kw">for</span> _ <span class="kw">in</span> <span class="num">1</span>...<span class="num">2</span> {
<span class="vr">hBar</span>.<span class="fn">addLine</span>(distance:<span class="num">30</span>*<span class="vr">scale</span>); <span class="vr">hBar</span>.<span class="fn">turn</span>(degrees:<span class="num">90</span>)
<span class="vr">hBar</span>.<span class="fn">addLine</span>(distance:<span class="num">4</span>*<span class="vr">scale</span>); <span class="vr">hBar</span>.<span class="fn">turn</span>(degrees:<span class="num">90</span>)
}
pen.<span class="fn">addShape</span>(pen: <span class="vr">hBar</span>)
}
<span class="fn">drawStGeorge</span>(scale: <span class="num">5</span>)</pre>
</div>
</div>
<div class="im-table-wrap">
<div class="im-table-header">IM1 Curriculum Connection</div>
<table class="im-table">
<thead><tr><th>Standard</th><th>Connection</th></tr></thead>
<tbody><tr><td>Geometry — Line Symmetry</td><td>St George's Cross has two lines of symmetry (horizontal and vertical) and 4-fold rotational symmetry — a symmetry group of order 4.</td></tr></tbody>
</table>
</div>
</div>
</section>
<section id="s12">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>Union Jack</h1>
<p class="lead">The Union Jack is a combination of St George's Cross, St Andrew's Cross, and St Patrick's Cross. Use your functions from sections 09–11 to layer all three on the same flag. The order is: blue background → St Andrew (white) → St Patrick (red, thinner) → St George (red, centred).</p>
<button class="complete-btn" data-id="s12" onclick="toggleComplete(this)">
<span class="btn-icon">○</span> Mark as Complete
</button>
</div>
<div class="article">
<div class="img-placeholder">
<span class="img-icon">📷</span>
<span class="img-name">05-12-union-jack.png</span>
<span class="img-hint">Image coming soon</span>
</div>
<button class="solution-toggle" onclick="toggleSolution(this,'sol12')">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
Show Solution
</button>
<div class="solution-body" id="sol12">
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Hint</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="cm">// Call your existing functions in order:</span>
<span class="cm">// 1. drawBlueBackground()</span>
<span class="cm">// 2. drawSaltire(color: .white, thickness: 8) // St Andrew</span>
<span class="cm">// 3. drawSaltire(color: .red, thickness: 4) // St Patrick</span>
<span class="cm">// 4. drawCentredCross(color: .red, width: 6) // St George</span></pre>
</div>
</div>
<div class="im-table-wrap">
<div class="im-table-header">IM1 Curriculum Connection</div>
<table class="im-table">
<thead><tr><th>Standard</th><th>Connection</th></tr></thead>
<tbody><tr><td>Geometry — Composition</td><td>The Union Jack is a superposition of three geometric designs. Function composition in code mirrors geometric composition — combining simple shapes to create complex ones.</td></tr></tbody>
</table>
</div>
</div>
</section>
<section id="s13">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>Filled Star</h1>
<p class="lead">Write a function <code>drawStar(points: Int, size: Double, color: Color)</code> that draws a filled star with any number of points. Use it to draw three stars of different sizes side by side.</p>
<button class="complete-btn" data-id="s13" onclick="toggleComplete(this)">
<span class="btn-icon">○</span> Mark as Complete
</button>
</div>
<div class="article">
<div class="img-placeholder">
<span class="img-icon">📷</span>
<span class="img-name">05-13-filled-star.png</span>
<span class="img-hint">Image coming soon</span>
</div>
<button class="solution-toggle" onclick="toggleSolution(this,'sol13')">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
Show Solution
</button>
<div class="solution-body" id="sol13">
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Solution</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="kw">func</span> <span class="fn">drawStar</span>(points: <span class="tp">Int</span>, size: <span class="tp">Double</span>, color: <span class="tp">Color</span>) {
<span class="kw">let</span> <span class="vr">angle</span> = <span class="tp">Double</span>(<span class="num">180</span> - <span class="num">180</span>/<span class="vr">points</span>) * <span class="num">2</span>
<span class="kw">let</span> <span class="vr">star</span> = <span class="tp">Pen</span>(); <span class="vr">star</span>.<span class="vr">fillColor</span> = <span class="vr">color</span>
<span class="kw">for</span> _ <span class="kw">in</span> <span class="num">1</span>...<span class="vr">points</span> {
<span class="vr">star</span>.<span class="fn">addLine</span>(distance: <span class="vr">size</span>)
<span class="vr">star</span>.<span class="fn">turn</span>(degrees: <span class="vr">angle</span>)
}
pen.<span class="fn">addShape</span>(pen: <span class="vr">star</span>)
}
<span class="fn">drawStar</span>(points: <span class="num">5</span>, size: <span class="num">80</span>, color: .<span class="vr">yellow</span>)</pre>
</div>
</div>
<div class="im-table-wrap">
<div class="im-table-header">IM1 Curriculum Connection</div>
<table class="im-table">
<thead><tr><th>Standard</th><th>Connection</th></tr></thead>
<tbody><tr><td>Geometry — Star Polygons</td><td>A {n/2} star polygon turns 2×360°/n at each vertex. The turn angle formula derives from the exterior angle theorem for star polygons.</td></tr></tbody>
</table>
</div>
</div>
</section>
<section id="s14">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>Australia</h1>
<p class="lead">The Australian flag has a blue background, the Union Jack in the top-left, a large 7-pointed star below it, and the Southern Cross (5 stars) on the right. Use your Union Jack and star functions to draw a simplified version.</p>
<button class="complete-btn" data-id="s14" onclick="toggleComplete(this)">
<span class="btn-icon">○</span> Mark as Complete
</button>
</div>
<div class="article">
<div class="img-placeholder">
<span class="img-icon">📷</span>
<span class="img-name">05-14-australia.png</span>
<span class="img-hint">Image coming soon</span>
</div>
<button class="solution-toggle" onclick="toggleSolution(this,'sol14')">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
Show Solution
</button>
<div class="solution-body" id="sol14">
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Hint</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="cm">// Use pen.move() to position each element:</span>
<span class="cm">// 1. Blue background rectangle</span>
<span class="cm">// 2. Union Jack scaled to top-left quadrant</span>
<span class="cm">// 3. drawStar(points: 7, ...) below Union Jack</span>
<span class="cm">// 4. Southern Cross: 4 large + 1 small star</span></pre>
</div>
</div>
<div class="im-table-wrap">
<div class="im-table-header">IM1 Curriculum Connection</div>
<table class="im-table">
<thead><tr><th>Standard</th><th>Connection</th></tr></thead>
<tbody><tr><td>Geometry — Scale & Position</td><td>Fitting the Union Jack into one quadrant requires halving its dimensions — a scale factor of 0.5. Positions are calculated relative to flag dimensions using fractions.</td></tr></tbody>
</table>
</div>
</div>
</section>
<section id="s15">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>Netherlands</h1>
<p class="lead">The Dutch flag is three equal horizontal stripes: red (top), white (middle), blue (bottom). Write a function <code>drawTricolour(color1: Color, color2: Color, color3: Color, width: Double, height: Double)</code> and draw the Netherlands flag.</p>
<button class="complete-btn" data-id="s15" onclick="toggleComplete(this)">
<span class="btn-icon">○</span> Mark as Complete
</button>
</div>
<div class="article">
<div class="img-placeholder">
<span class="img-icon">📷</span>
<span class="img-name">05-15-netherlands.png</span>
<span class="img-hint">Image coming soon</span>
</div>
<button class="solution-toggle" onclick="toggleSolution(this,'sol15')">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
Show Solution
</button>
<div class="solution-body" id="sol15">
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Solution</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="kw">func</span> <span class="fn">drawStripe</span>(width: <span class="tp">Double</span>, height: <span class="tp">Double</span>, color: <span class="tp">Color</span>) {
<span class="kw">let</span> <span class="vr">s</span> = <span class="tp">Pen</span>(); <span class="vr">s</span>.<span class="vr">fillColor</span> = <span class="vr">color</span>
<span class="kw">for</span> _ <span class="kw">in</span> <span class="num">1</span>...<span class="num">2</span> {
<span class="vr">s</span>.<span class="fn">addLine</span>(distance: <span class="vr">width</span>); <span class="vr">s</span>.<span class="fn">turn</span>(degrees:<span class="num">90</span>)
<span class="vr">s</span>.<span class="fn">addLine</span>(distance: <span class="vr">height</span>); <span class="vr">s</span>.<span class="fn">turn</span>(degrees:<span class="num">90</span>)
}
pen.<span class="fn">addShape</span>(pen: <span class="vr">s</span>)
}
<span class="fn">drawStripe</span>(width: <span class="num">200</span>, height: <span class="num">40</span>, color: .<span class="vr">red</span>)
pen.<span class="fn">turn</span>(degrees: <span class="num">270</span>); pen.<span class="fn">move</span>(distance: <span class="num">40</span>); pen.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="fn">drawStripe</span>(width: <span class="num">200</span>, height: <span class="num">40</span>, color: .<span class="vr">white</span>)
pen.<span class="fn">turn</span>(degrees: <span class="num">270</span>); pen.<span class="fn">move</span>(distance: <span class="num">40</span>); pen.<span class="fn">turn</span>(degrees: <span class="num">90</span>)
<span class="fn">drawStripe</span>(width: <span class="num">200</span>, height: <span class="num">40</span>, color: .<span class="vr">blue</span>)</pre>
</div>
</div>
<div class="im-table-wrap">
<div class="im-table-header">IM1 Curriculum Connection</div>
<table class="im-table">
<thead><tr><th>Standard</th><th>Connection</th></tr></thead>
<tbody><tr><td>Geometry — Area</td><td>Three equal horizontal stripes each occupy 1/3 of the total area. Total area = width × height; each stripe area = width × (height/3).</td></tr></tbody>
</table>
</div>
</div>
</section>
<section id="s16">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>France</h1>
<p class="lead">The French tricolour has three <em>vertical</em> stripes: blue, white, red. Reuse your stripe function from the Netherlands exercise, but rotate it 90° for vertical stripes.</p>
<button class="complete-btn" data-id="s16" onclick="toggleComplete(this)">
<span class="btn-icon">○</span> Mark as Complete
</button>
</div>
<div class="article">
<div class="img-placeholder">
<span class="img-icon">📷</span>
<span class="img-name">05-16-france.png</span>
<span class="img-hint">Image coming soon</span>
</div>
<button class="solution-toggle" onclick="toggleSolution(this,'sol16')">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
Show Solution
</button>
<div class="solution-body" id="sol16">
<div class="code-wrap">
<div class="code-header"><span class="code-lang">Hint</span><button class="code-copy" onclick="copyCode(this)">Copy</button></div>
<pre><span class="cm">// Draw three side-by-side rectangles (each 1/3 the total width)</span>
<span class="cm">// After each stripe, move right by stripe width to start the next</span>
<span class="fn">drawStripe</span>(width: <span class="num">60</span>, height: <span class="num">120</span>, color: .<span class="vr">blue</span>)
pen.<span class="fn">move</span>(distance: <span class="num">60</span>)
<span class="fn">drawStripe</span>(width: <span class="num">60</span>, height: <span class="num">120</span>, color: .<span class="vr">white</span>)
pen.<span class="fn">move</span>(distance: <span class="num">60</span>)
<span class="fn">drawStripe</span>(width: <span class="num">60</span>, height: <span class="num">120</span>, color: .<span class="vr">red</span>)</pre>
</div>
</div>
<div class="im-table-wrap">
<div class="im-table-header">IM1 Curriculum Connection</div>
<table class="im-table">
<thead><tr><th>Standard</th><th>Connection</th></tr></thead>
<tbody><tr><td>Geometry — Transformations</td><td>Rotating the stripe from horizontal to vertical is a 90° transformation. The same function with swapped width/height parameters achieves this in code.</td></tr></tbody>
</table>
</div>
</div>
</section>
<!-- ════════════════════════════════════════
SECTION 17 — Positions
════════════════════════════════════════ -->
<section id="s17">
<div class="section-hero">
<span class="section-tag exercise">◆ Exercise</span>
<h1>Positions</h1>
<p class="lead">Update your flag functions to accept an <code>x</code> and <code>y</code> parameter so the flag can be drawn at any position on the canvas. Draw the flags of France, Netherlands, and Denmark side by side on the same canvas using positions.</p>
<button class="complete-btn" data-id="s17" onclick="toggleComplete(this)">
<span class="btn-icon">○</span> Mark as Complete
</button>
</div>
<div class="article">
<div class="img-placeholder">
<span class="img-icon">📷</span>
<span class="img-name">05-17-positions.png</span>
<span class="img-hint">Image coming soon</span>
</div>
<button class="solution-toggle" onclick="toggleSolution(this,'sol17')">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
Show Solution