Mason’s Nerdy Icon — Leave No Trace-y
Same artwork. Functions that stand alone — every one starts and ends at a known place.
Stage 3: the architecture upgrade. Comment out any feature in main() and the rest still runs.
The Code, Independent
Every function starts by calling
penup() → goto(x, y) → setheading(angle) to establish its own position.Every function ends by calling
penup() → goto(PARK_X, PARK_Y) to leave Tracy at a neutral spot.No function assumes anything about where the previous one stopped.
Stage 2 organized Mason’s code into named functions — a big improvement — but each function
depended on arriving at the exact position where the previous one ended.
Comment out draw_glasses() in Stage 2 and the eyes end up in the wrong place.
Stage 3 fixes that: every function navigates to its own starting coordinates using goto().
- Face is centered at canvas origin
(0, 0)— simpler coordinate math than Stage 1’s offset. - Every function opens with
penup(); goto(x, y); setheading(angle)— guaranteed starting state. - Every function closes with
penup(); goto(PARK_X, PARK_Y)— guaranteed ending state. reposition_to_mouth()is eliminated —draw_mouth()justgoto()s to(0, -35)directly.draw_cheeks()usesgoto()for every dot — zero relative navigation between dots.- Any line in
main()can be commented out and the remaining features draw correctly.
Output
Identical to Stage 1 & 2.
Same artwork — truly independent functions.
Save your CodeHS output as
images/claudesRefactoredNerd2.png
All Three Stages
Open all three pages side by side to see the full progression: Stage 1 — Mason’s original 154-line flat script; Stage 2 — the same commands organized into named functions and constants; Stage 3 — functions that stand alone because every one navigates to its own starting point. The artwork is identical in all three. Only the structure changes.