Skip to content

Commit 04c0850

Browse files
committed
Added chapter 4 and modified the content generation to hide the drawing area from the skulpt templates if no drawing is needed. The textarea now fills the entire width of the content area.
1 parent 5d5eac2 commit 04c0850

14 files changed

Lines changed: 1032 additions & 57 deletions

File tree

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"randint",
2626
"readlines",
2727
"setheading",
28+
"skulkt",
2829
"Skulpt",
2930
"Spyder",
3031
"startswith",

CONTENT-GENERATION-GUIDELINES.md

Lines changed: 83 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,27 @@ Keep programs short enough that students can read the whole thing at a glance:
100100
- **Mid-course labs (Chapters 6–18):** 8–20 lines of Python
101101
- **Advanced labs (Chapters 19+):** no strict limit, but prefer several short focused labs over one long one
102102

103-
### When Not to Use Turtle Graphics
103+
### When to Use Each Lab Type
104104

105-
From Chapter 19 onward, turtle is used selectively for visualization projects.
106-
Pure language concepts (string methods, dictionaries, error handling, etc.) may use
107-
text-output Skulpt labs that write to the `<pre id="output">` element instead of drawing
108-
on the canvas. The same HTML block structure applies — just omit turtle-specific code.
105+
There are two Skulpt lab layouts. Choose based on whether the program uses turtle graphics:
106+
107+
| Situation | Lab type | HTML class |
108+
|-----------|----------|------------|
109+
| Program uses `import turtle` or any turtle command | **Drawing lab** | *(no extra class — default)* |
110+
| Program uses only `print()`, variables, loops, functions, etc. | **Text-only lab** | `class="skulpt-text-only"` |
111+
112+
**Drawing labs** (Chapters 1–18 turtle lessons) show a 400 × 400 px canvas to the right of the
113+
code editor where the turtle draws.
114+
115+
**Text-only labs** hide the canvas panel entirely; the code editor stretches to fill the full
116+
content width. Use these for any program that produces only text output — `print()` calls,
117+
variable values, string results, etc. This layout is the default from Chapter 19 onward, and
118+
can also appear in earlier chapters for the rare non-turtle concept (e.g., a `print()`-only
119+
variable lesson).
120+
121+
Never put a text-only lab in a lesson that also needs the canvas, and never put a drawing
122+
lab in a lesson whose programs do not call any turtle commands — the empty canvas just
123+
wastes space and confuses students.
109124

110125
---
111126

@@ -452,14 +467,24 @@ then run it to check!
452467

453468
### Skulpt HTML Block
454469

455-
Every Skulpt lab uses this exact HTML block. The CDN scripts load Skulpt;
456-
`skulpt.js` (via `extra_javascript`) and `skulpt.css` (via `extra_css`)
457-
provide the shared functions and styles.
470+
There are two lab templates. Pick based on whether the program uses turtle graphics
471+
(see [When to Use Each Lab Type](#when-to-use-each-lab-type)).
472+
473+
The CDN `<script>` tags must appear **once per page**, before the first lab block.
474+
`skulpt.js` (via `extra_javascript`) and `skulpt.css` (via `extra_css`) provide the
475+
shared runtime and styles — do not add inline `<style>` or `<script>` tags.
458476

459477
```html
460478
<script src="https://skulpt.org/js/skulpt.min.js"></script>
461479
<script src="https://skulpt.org/js/skulpt-stdlib.js"></script>
480+
```
462481

482+
#### Drawing Lab (turtle programs)
483+
484+
Use when the program calls `import turtle` or any turtle command.
485+
The canvas appears to the right of the code editor.
486+
487+
```html
463488
<div id="skulpt-lab">
464489
<div id="editor-container">
465490
<textarea id="code" spellcheck="false">PYTHON CODE HERE
@@ -476,18 +501,45 @@ provide the shared functions and styles.
476501
</div>
477502
```
478503

479-
**Rules:**
504+
#### Text-Only Lab (print/variables/logic — no turtle)
505+
506+
Use when the program produces only text output. Add `class="skulpt-text-only"` to
507+
the outer div. The canvas container is hidden by CSS; the editor fills the full
508+
content width. The `turtle-target` div must still be present so `runSkulpt()` can
509+
initialise without errors — it just isn't visible.
510+
511+
```html
512+
<div id="skulpt-lab" class="skulpt-text-only">
513+
<div id="editor-container">
514+
<textarea id="code" spellcheck="false">PYTHON CODE HERE
515+
</textarea>
516+
<div id="button-row">
517+
<button id="run-btn" onclick="runSkulpt()">&#9654; Run</button>
518+
<button id="reset-btn" onclick="resetSkulpt()">&#8635; Reset</button>
519+
</div>
520+
<pre id="output"></pre>
521+
</div>
522+
<div id="canvas-container">
523+
<div id="turtle-target"></div>
524+
</div>
525+
</div>
526+
```
527+
528+
#### Rules that apply to both templates
529+
480530
- The Python code inside `<textarea>` must match the Sample Code block exactly
481-
- Do not add inline `<style>` or `<script>` tags — all CSS/JS is centralized
482-
- The first lab on a page uses the plain IDs above — `skulpt.js` depends on them
483-
- **Do not set a `height` or `rows` attribute on the `<textarea>`**`skulpt.js` counts the lines of code on page load and sets the textarea height automatically so all code is visible without scrolling
531+
- **Do not set a `height` or `rows` attribute on the `<textarea>`**`skulpt.js` auto-sizes it on page load so all code is visible without scrolling
532+
- The first lab on a page uses the plain IDs above; `skulpt.js` depends on them
484533

485-
**Multiple labs on one page (Learning Checks, etc.):**
534+
#### Multiple labs on one page (Learning Checks, etc.)
486535

487-
Every lab after the first must use a `-2`, `-3`, … suffix on every ID, and pass
488-
the matching suffix to the button `onclick` handlers:
536+
Every lab after the first must use a `-2`, `-3`, … suffix on **every** ID, and pass
537+
the matching suffix to the button `onclick` handlers. The `skulpt-text-only` class
538+
applies to multiple labs independently — a page may have a drawing lab first and a
539+
text-only lab second, or vice versa.
489540

490541
```html
542+
<!-- Second drawing lab -->
491543
<div id="skulpt-lab-2">
492544
<div id="editor-container-2">
493545
<textarea id="code-2" spellcheck="false">PYTHON CODE HERE
@@ -502,9 +554,24 @@ the matching suffix to the button `onclick` handlers:
502554
<div id="turtle-target-2"></div>
503555
</div>
504556
</div>
557+
558+
<!-- Second text-only lab -->
559+
<div id="skulpt-lab-2" class="skulpt-text-only">
560+
<div id="editor-container-2">
561+
<textarea id="code-2" spellcheck="false">PYTHON CODE HERE
562+
</textarea>
563+
<div id="button-row-2">
564+
<button id="run-btn-2" onclick="runSkulpt('-2')">&#9654; Run</button>
565+
<button id="reset-btn-2" onclick="resetSkulpt('-2')">&#8635; Reset</button>
566+
</div>
567+
<pre id="output-2"></pre>
568+
</div>
569+
<div id="canvas-container-2">
570+
<div id="turtle-target-2"></div>
571+
</div>
572+
</div>
505573
```
506574

507-
The `skulpt.js` and `skulpt.css` files both support the `-2` / `-3` suffix pattern.
508575
Do not add the `<script>` CDN tags a second time — one copy per page is enough.
509576

510577
---

docs/chapters/01-welcome-to-python/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Edit the code below and click **Run** to see the result right on this page. No a
116116
<script src="https://skulpt.org/js/skulpt.min.js"></script>
117117
<script src="https://skulpt.org/js/skulpt-stdlib.js"></script>
118118

119-
<div id="skulpt-lab">
119+
<div id="skulpt-lab" class="skulpt-text-only">
120120
<div id="editor-container">
121121
<textarea id="code" spellcheck="false">print("Hello, world!")
122122
print("My name is Monty.")

docs/chapters/02-python-code-structure/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ print(haiku)
6868
<script src="https://skulpt.org/js/skulpt.min.js"></script>
6969
<script src="https://skulpt.org/js/skulpt-stdlib.js"></script>
7070

71-
<div id="skulpt-lab">
71+
<div id="skulpt-lab" class="skulpt-text-only">
7272
<div id="editor-container">
7373
<textarea id="code" spellcheck="false">haiku = """An old silent pond.
7474
A frog jumps into the pond.

docs/chapters/03-variables-and-numbers/index.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ No account needed — everything runs in your browser.
8383
<script src="https://skulpt.org/js/skulpt.min.js"></script>
8484
<script src="https://skulpt.org/js/skulpt-stdlib.js"></script>
8585

86-
<div id="skulpt-lab">
86+
<div id="skulpt-lab" class="skulpt-text-only">
8787
<div id="editor-container">
8888
<textarea id="code" spellcheck="false">score = 10
8989
lives = 3
@@ -149,6 +149,7 @@ The table below shows common naming mistakes and their snake_case fixes:
149149
| `myscore` | Words run together — hard to read | `my_score` |
150150
| `MyScore` | Capital letters belong to a different naming style | `my_score` |
151151
| `my score` | Spaces are not allowed in variable names | `my_score` |
152+
| `my-score` | Python reads the dash as **subtraction**`my - score` — not a name! | `my_score` |
152153
| `x` | Too vague — what does `x` mean? | `player_score` |
153154
| `s` | Single letters give no information | `lives_remaining` |
154155

@@ -165,7 +166,7 @@ When that happens, a good name is the difference between code you can read and c
165166

166167
!!! mascot-warning "Naming Pitfalls!"
167168
![Monty warning](../../img/mascot/warning.png){ class="mascot-admonition-img" }
168-
Three traps beginners fall into: (1) single-letter names like `x` or `n` that tell you nothing, (2) capital letters that break the snake_case style Python expects, and (3) accidentally naming a variable after a Python keyword. If Python gives you a `SyntaxError` the moment you assign a value, check whether your variable name is a keyword like `print` or `list`!
169+
Watch out for the dash! If you write `my-score` instead of `my_score`, Python reads the dash as a minus sign and thinks you are subtracting a variable called `score` from a variable called `my`. Use an **underscore** (`_`), never a dash (`-`), to join words in a name. Other common traps: single-letter names like `x` that tell you nothing, capital letters that break snake_case, and accidentally using a Python keyword as your variable name.
169170

170171
## Integers: Whole Numbers
171172

@@ -246,7 +247,7 @@ print(score)
246247

247248
## Try It Now — Reassignment
248249

249-
<div id="skulpt-lab-2">
250+
<div id="skulpt-lab-2" class="skulpt-text-only">
250251
<div id="editor-container-2">
251252
<textarea id="code-2" spellcheck="false">score = 10
252253
print(score)
@@ -340,7 +341,7 @@ You will learn much more about classes later in the course.
340341
![Monty thinking](../../img/mascot/thinking.png){ class="mascot-admonition-img" }
341342
The program below creates two variables — `player_score` and `bonus_points`. It prints `player_score` just fine, but something is missing: `bonus_points` never gets printed. Add **one line** so the output shows both numbers, one on each line.
342343

343-
<div id="skulpt-lab-3">
344+
<div id="skulpt-lab-3" class="skulpt-text-only">
344345
<div id="editor-container-3">
345346
<textarea id="code-3" spellcheck="false">player_score = 42
346347
bonus_points = 10

0 commit comments

Comments
 (0)