Intermediate — Day 1
Libraries & Turtle Graphics
Day Schedule
Online
| Time | Activity |
|---|---|
| 10:00 | Welcome + Demo Show the complete snake game — this is the week's goal |
| 10:20 | Pre-Assessment Link provided separately |
| 10:35 | Intro to Libraries What import does; demo NameError without it |
| 10:55 | Screen Setup bgcolor, setup, tracer(0); coordinate system on whiteboard |
| 11:05 | Snake Head shape, color, penup, goto; screen.update() and mainloop() |
| 11:10 | Break |
| 11:20 | Breakout Groups Guided coding: get screen + head visible |
| 12:20 | Reminders |
In-Person
| Time | Activity |
|---|---|
| 8:00 | Welcome + Demo Show the complete snake game — this is the week's goal |
| 8:20 | Pre-Assessment Link provided separately |
| 8:35 | Intro to Libraries What import does; demo NameError without it |
| 8:55 | Screen Setup bgcolor, setup, tracer(0); coordinate system on whiteboard |
| 9:15 | Snake Head shape, color, penup, goto; screen.update() and mainloop() |
| 9:40 | Break |
| 9:50 | Breakout Groups Guided coding: get screen + head visible |
| 11:00 | Break |
| 11:10 | Extra Activity Draw a repeating pattern with a Turtle loop |
| 11:50 | Open Coding Catch up or experiment with Turtle settings |
| 12:20 | Reminders |
Learning Objectives
- Know what a library is and how import works
- Set up the Turtle screen with bgcolor, setup, and tracer
- Create and position a Turtle object as the snake head
- Understand the coordinate system: (0,0) is center, x=right, y=up
- Keep the window open with screen.mainloop()
Main Topic
# INSTRUCTOR — Day 1: Libraries & Turtle Graphics (Intermediate)
# -----------------------------------------------
# TEACH: Students already know variables, types, and basic conditionals.
# Move quickly through the review. The real focus is the Turtle library.
# Key vocabulary: library, import, screen, turtle object, tracer, penup/pendown.
import turtle
# TEACH: import makes an external library available. Without it, turtle is undefined.
# Demo: try turtle.Screen() before the import line → NameError.
# --- Screen setup ---
screen = turtle.Screen()
screen.bgcolor("black") # TEACH: color names are strings
screen.setup(width=600, height=600)
screen.tracer(0) # TEACH: tracer(0) disables automatic drawing.
# We must call screen.update() manually.
# This is how we control animation speed later.
# --- Turtle object ---
t = turtle.Turtle()
t.shape("square") # TEACH: shapes available: "square", "circle", "arrow", "turtle"
t.color("white")
t.penup() # TEACH: penup means moving doesn't draw a line
t.goto(0, 0) # TEACH: (0,0) is the CENTER of the screen
screen.update() # TEACH: without this, nothing appears on screen with tracer(0)
# TEACH: coordinate system — show the axes on a diagram
# x: negative = left, positive = right
# y: negative = down, positive = up
# Center (0,0), corners at approx ±300 on a 600×600 screen
screen.mainloop() # TEACH: keeps the window open; without it the window closes instantly
Project — Snake Screen & Head
# INSTRUCTOR — Day 1: Project: Snake: Screen & Head Setup (Intermediate)
# -----------------------------------------------
# TEACH: This is the foundation of every future session.
# Every student must leave Day 1 with this file working.
# Check: black window open, white square visible in the center.
# Common issue: window appears and immediately closes — they forgot screen.mainloop().
import turtle
# --- Screen ---
screen = turtle.Screen()
screen.title("Snake Game") # TEACH: title() sets the window title bar text
screen.bgcolor("black")
screen.setup(width=600, height=600)
screen.tracer(0)
# --- Snake head ---
head = turtle.Turtle()
head.shape("square") # TEACH: the snake body will also use squares
head.color("white")
head.penup() # TEACH: we NEVER want head to draw lines as it moves
head.goto(0, 0)
# TEACH: naming convention — we call it 'head' not 't' because it will have a specific role.
# Every future Day builds on these exact variable names. Don't rename them.
screen.update()
screen.mainloop()
Extra — Draw a Pattern
# INSTRUCTOR — Day 1: Extra Activity: Draw a Pattern (Intermediate)
# -----------------------------------------------
# TEACH: for loops + Turtle = immediate visual feedback.
# Key insight: turn angle = 360 / number of sides.
# Students should try different values and see the pattern emerge.
import turtle
turtle.speed(5)
turtle.color("purple")
# Draw a hexagon (6 sides, 60 degrees each)
for i in range(6):
turtle.forward(100)
turtle.right(60) # 360 / 6 = 60
turtle.done()
# TEACH: what shape do you get with range(3), right(120)? Triangle.
# range(4), right(90)? Square. range(8), right(45)? Octagon.
# TEACH: challenge — draw the shape 4 times by wrapping in another for loop
# Students must figure out how to move the turtle between drawings
# Challenge extension:
import turtle as t
t.speed(0)
positions = [(-150, 0), (150, 0), (0, 150), (0, -150)]
for pos in positions:
t.penup()
t.goto(pos) # pos is a tuple (x, y) — goto accepts it directly
t.pendown()
for _ in range(6):
t.forward(60)
t.right(60)
t.done()