Students can try following practice first:
for loops and angle control, write a function that draws a classic 5-point star or an n-point star. Then create a rosette by rotating and stamping multiple stars evenly around a circle. As a challenge, implement a polygon spiral where the step length gradually changes and colors cycle, producing a vortex-like pattern.Sample Output Description:
The window first shows 12 colored 5-point stars arranged evenly around the center, forming a rosette. Then it clears the screen and draws a 7-sided spiral whose step length grows gradually while cycling through five colors, producing an outward vortex. The console prints status lines such as [INFO] Rosette done: radius=180, copies=12 and [INFO] Polygon spiral done: sides=7, turns=120.
Answer example:
import turtle
import random
screen = turtle.Screen()
screen.setup(800, 600)
screen.title("Stars & Patterns")
t = turtle.Turtle()
t.hideturtle()
t.speed(0) # fastest drawing
t.pensize(2)
def draw_star(size=120, points=5, color="gold"):
t.color(color)
t.begin_fill()
turn = 180 - (180 / points)
for _ in range(points):
t.forward(size)
t.right(turn)
t.end_fill()
def star_rosette(radius=180, copies=10, size=80):
t.penup()
t.goto(0, 0)
t.setheading(90)
for i in range(copies):
angle = 360 / copies * i
t.setheading(angle)
t.forward(radius)
t.pendown()
draw_star(size=size, points=5, color=random.choice(
["gold", "orange", "tomato", "hotpink", "deepskyblue", "limegreen"]))
t.penup()
t.goto(0, 0)
print(f"[INFO] Rosette done: radius={radius}, copies={copies}")
def polygon_spiral(sides=6, turns=80, step_start=5, step_delta=2):
t.penup()
t.goto(0, 0)
t.setheading(0)
t.pendown()
colors = ["#ff6b6b", "#feca57", "#1dd1a1", "#54a0ff", "#5f27cd"]
step = step_start
for i in range(turns):
t.color(colors[i % len(colors)])
t.forward(step)
t.right(360 / sides)
step += step_delta
print(f"[INFO] Polygon spiral done: sides={sides}, turns={turns}")
t.penup(); t.goto(0, -200); t.pendown()
t.color("gray"); t.write("Drawing Rosette...", align="center", font=("Arial", 14, "normal"))
t.clear()
star_rosette(radius=180, copies=12, size=70)
t.penup(); t.goto(0, 0); t.pendown()
t.write("Drawing Polygon Spiral...", align="center", font=("Arial", 14, "normal"))
t.clear()
polygon_spiral(sides=7, turns=120, step_start=3, step_delta=2)
turtle.done()
1–6 to change colors, +/- to adjust pen size, space to toggle pen up/down, U to undo, C to clear, and H to show help. Also display a live HUD at the top-left showing the current color and pen size.Sample Output Description:
The app opens a 900×650 window with a HUD at top-left showing current color and pen size. Left-drag draws freely. Pressing 2 switches to red; + or - adjusts pen size; space toggles pen up/down; U undoes the last stroke; C clears; H prints and displays help in the HUD. On slower machines, keep screen.tracer(False) and call screen.update() periodically for smoother drawing. Some keyboards require binding "=" in addition to "+" for size increase.
Answer example:
import turtle
screen = turtle.Screen()
screen.setup(900, 650)
screen.title("My Drawing Board")
screen.tracer(False)
pen = turtle.Turtle()
pen.speed(0)
pen.shape("circle")
pen.shapesize(0.6, 0.6)
pen.color("black")
pen.pensize(3)
pen.penup()
hud = turtle.Turtle()
hud.hideturtle()
hud.penup()
hud.goto(-430, 290)
is_drawing = False
colors = ["black", "red", "orange", "green", "blue", "purple"]
def draw_hud():
hud.clear()
hud.write(f"Color: {pen.pencolor()} | Size: {pen.pensize()} "
f"(1-6 colors, +/- size, SPACE pen up/down, U undo, C clear, H help)",
font=("Arial", 12, "normal"))
screen.update()
def show_help():
help_text = (
"Left-drag: draw | 1-6: color | +/-: size | SPACE: pen up/downn"
"U: undo | C: clear | H: help"
)
print(help_text)
hud.clear()
hud.write("HELP: " + help_text, font=("Arial", 12, "normal"))
screen.update()
def start_draw(x, y):
global is_drawing
is_drawing = True
pen.goto(x, y)
pen.pendown()
draw_hud()
def drawing(x, y):
if is_drawing:
pen.goto(x, y)
screen.update()
def stop_draw(x, y):
global is_drawing
is_drawing = False
pen.penup()
draw_hud()
def toggle_pen():
if pen.isdown():
pen.penup()
else:
pen.pendown()
draw_hud()
def inc_size():
pen.pensize(min(pen.pensize() + 1, 30))
draw_hud()
def dec_size():
pen.pensize(max(pen.pensize() - 1, 1))
draw_hud()
def set_color_idx(idx):
c = colors[idx]
pen.color(c)
draw_hud()
def do_undo():
try:
pen.undo()
except turtle.TurtleGraphicsError:
pass
draw_hud()
def do_clear():
pen.clear()
draw_hud()
screen.listen()
screen.onscreenclick(start_draw, 1)
screen.ondrag(drawing, 1)
screen.onrelease(stop_draw, 1)
screen.onkey(toggle_pen, "space")
screen.onkey(inc_size, "+")
screen.onkey(inc_size, "=")
screen.onkey(dec_size, "-")
screen.onkey(do_undo, "u")
screen.onkey(do_clear, "c")
screen.onkey(show_help, "h")
screen.onkey(lambda: set_color_idx(0), "1")
screen.onkey(lambda: set_color_idx(1), "2")
screen.onkey(lambda: set_color_idx(2), "3")
screen.onkey(lambda: set_color_idx(3), "4")
screen.onkey(lambda: set_color_idx(4), "5")
screen.onkey(lambda: set_color_idx(5), "6")
draw_hud()
screen.update()
turtle.done()
In this unit, we learned how to make our code visible. Using the turtle graphics library, we moved beyond printing words and numbers — we learned to control a digital pen and draw shapes, patterns, and art on the screen. Starting with simple movements and turns, we discovered how coordinates and angles shape geometry, and how loops can generate repeating designs automatically. We saw how programming and math can work beautifully together.