STARLEAP / PYTHON TURTLE

Build 2026.09.17-001210-0400

On this page

6. Turtle Scene Builder: Many Functions Make One Picture

You have drawn polygons, flowers, and curve designs. Today you will combine several named chunks into one complete scene.

A scene program is easier to read when each drawing job has its own function. The main program can then call those functions in the order the picture should appear.

Start With A Turtle File

Save a new file named turtle_scene.py.

Start with this template.

CODE
import turtle

screen = turtle.Screen()
screen.setup(600, 800, 0, 0)
t = turtle.Turtle()
t.speed(0)

# Your scene code goes here.

screen.mainloop()

Run the program. A blank turtle window is fine. Close the turtle window before you change the code again.

Step 1 - Jump Without Drawing

Replace the middle comment with this test line.

EDIT VIEW - Gray = already there; dark = add or change
t.speed(0)

t.teleport(-80, -220)

screen.mainloop()

Run the program. The turtle should jump to a new spot without drawing a travel line.

t.teleport(x, y) moves the turtle to an exact spot. It is useful when your scene has pieces in different places.

Step 2 - Draw A Filled Square

Replace the t.teleport(...) test line with this function.

EDIT VIEW - Gray = already there; dark = add or change
t.speed(0)

def draw_square(length, ink):
    t.color(ink)
    t.begin_fill()
    for i in range(4):
        t.forward(length)
        t.left(90)
    t.end_fill()

screen.mainloop()

Then add a call at the bottom.

EDIT VIEW - Gray = already there; dark = add or change
def draw_square(length, ink):
    ...

t.teleport(-80, -220)
draw_square(160, 'tan')

screen.mainloop()

Run the program.

t.begin_fill() starts saving the outline of the shape. t.end_fill() fills the shape with the turtle's current color.

Step 3 - Add A Roof

Add this triangle function above your calls.

EDIT VIEW - Gray = already there; dark = add or change
def draw_square(length, ink):
    ...

def draw_triangle(length, ink):
    t.color(ink)
    t.begin_fill()
    for i in range(3):
        t.forward(length)
        t.left(120)
    t.end_fill()

t.teleport(-80, -220)
...

Then call it after the square.

EDIT VIEW - Gray = already there; dark = add or change
t.teleport(-80, -220)
draw_square(160, 'tan')

t.teleport(-100, -60)
draw_triangle(200, 'brown')

screen.mainloop()

Run the program.

The order of the calls matters. Python draws the square first, then the roof.

Step 4 - Make A House Function

The square and roof belong together. Put them inside one function.

EDIT VIEW - Gray = already there; dark = add or change
def draw_triangle(length, ink):
    ...

def draw_house(x_position, y_position):
    roof_x_offset = 0
    roof_y_offset = 0
    t.teleport(x_position, y_position)
    draw_square(160, 'tan')
    t.teleport(x_position + roof_x_offset, y_position + roof_y_offset)
    draw_triangle(200, 'brown')

draw_house(-80, -220)

screen.mainloop()

Run the program.

The roof starts in the same place as the square. That is okay for now.

Change only these two variables, then run again:

CODE
roof_x_offset = 0
roof_y_offset = 0

Keep changing those two numbers until the roof sits where you like it. A positive x offset moves the roof right. A negative x offset moves it left. A positive y offset moves it up.

The draw_house(...) function calls other functions. A function is allowed to use smaller helper functions inside its chunk.

Step 5 - Plan The Rest Of Your Scene

Your house is the example. Now choose what else belongs in your scene.

Pick at least two new drawing jobs. Each one should become its own function.

Possible function ideas:

Before you code, choose two ideas and decide what arguments each function needs.

Step 6 - Add Your First New Function

Use this pattern to add your own function above draw_house(-80, -220).

EDIT VIEW - Gray = already there; dark = add or change
def draw_house(x_position, y_position):
    ...

def draw_idea_name(x_position, y_position):
    t.teleport(x_position, y_position)
    # Draw your shape here.

draw_house(-80, -220)

Rename the function so its name says what it draws. Then replace the comment with turtle drawing code.

Call your new function after the house.

EDIT VIEW - Gray = already there; dark = add or change
draw_house(-80, -220)
draw_idea_name(190, 220)

screen.mainloop()

Run the program.

If your scene does not change, check both places: the function definition and the function call.

Step 7 - Add More Scene Functions

Add at least one more function of your own. You may use circles, polygons, arcs, colors, loops, or other functions you already wrote.

EDIT VIEW - Gray = already there; dark = add or change
def draw_idea_name(x_position, y_position):
    ...

def draw_another_idea(x_position, y_position, size):
    t.teleport(x_position, y_position)
    # Draw another part of your scene here.
...

Call each scene function near the bottom of your program.

EDIT VIEW - Gray = already there; dark = add or change
draw_house(-80, -220)
draw_idea_name(190, 220)
draw_another_idea(-220, -230, 40)

screen.mainloop()

Run the program.

Final Project - Build Your Scene

Use this program as a scene starter. It gives you the house. You create the rest.

CODE
import turtle
screen = turtle.Screen()
screen.setup(600, 800, 0, 0)
t = turtle.Turtle()
t.speed(0)
def draw_square(length, ink):
    t.color(ink)
    t.begin_fill()
    for i in range(4):
        t.forward(length)
        t.left(90)
    t.end_fill()
def draw_triangle(length, ink):
    t.color(ink)
    t.begin_fill()
    for i in range(3):
        t.forward(length)
        t.left(120)
    t.end_fill()
def draw_house(x_position, y_position):
    roof_x_offset = 0
    roof_y_offset = 0
    t.teleport(x_position, y_position)
    draw_square(160, 'tan')
    t.teleport(x_position + roof_x_offset, y_position + roof_y_offset)
    draw_triangle(200, 'brown')

# Add your own scene functions here.

def draw_idea_name(x_position, y_position):
    t.teleport(x_position, y_position)
    # Draw your first idea here.

draw_house(-80, -220)

# Call your own scene functions here.
draw_idea_name(190, 220)

screen.mainloop()

Run the program.

Make the scene yours. Add more functions, call them in different places, and change one argument at a time so you can see what each change controls.

Teacher Check

Show your scene. Then point to:

Say this out loud: "A scene is easier to build when each drawing job has a clear function name."