🐍 Python Tutorial
import turtle

screen = turtle.Screen()
screen.setup(400, 400)
screen.bgcolor('skyblue')

pen = turtle.Turtle()
pen.hideturtle()
pen.speed(0)

def circle(x, y, radius, color):
    pen.penup()
    pen.goto(x, y - radius)
    pen.pendown()
    pen.color(color)
    pen.begin_fill()
    pen.circle(radius)
    pen.end_fill()

def dot(x, y, size, color):
    pen.penup()
    pen.goto(x, y)
    pen.color(color)
    pen.dot(size)

def rect(x, y, width, height, color):
    pen.penup()
    pen.goto(x, y)
    pen.setheading(0)
    pen.pendown()
    pen.color(color)
    pen.begin_fill()
    for length in [width, height, width, height]:
        pen.forward(length)
        pen.left(90)
    pen.end_fill()

def triangle(x, y, size, color):
    pen.penup()
    pen.goto(x, y)
    pen.setheading(0)
    pen.pendown()
    pen.color(color)
    pen.begin_fill()
    for i in range(3):
        pen.forward(size)
        pen.left(120)
    pen.end_fill()

circle(0, 0, 80, 'yellow')
dot(-30, 20, 15, 'black')
dot(30, 20, 15, 'black')
rect(-25, -30, 50, 15, 'red')
triangle(-15, 0, 30, 'orange')

screen.mainloop()

Project 4 — Step 4 of 5

⭐ Step 4 — Triangles

➡️ Add a triangle nose to your face.

A triangle is 3 lines, turning 120 degrees each time (because 3 × 120 = 360, a full circle).

✏️ What to type

Add a triangle() helper function:

def triangle(x, y, size, color):
    pen.penup()
    pen.goto(x, y)
    pen.setheading(0)
    pen.pendown()
    pen.color(color)
    pen.begin_fill()
    for i in range(3):
        pen.forward(size)
        pen.left(120)
    pen.end_fill()

Then add a nose call after the mouth:

triangle(-15, 0, 30, 'orange')
import turtle

screen = turtle.Screen()
screen.setup(400, 400)
screen.bgcolor('skyblue')

pen = turtle.Turtle()
pen.hideturtle()
pen.speed(0)

def circle(x, y, radius, color):
    pen.penup()
    pen.goto(x, y - radius)
    pen.pendown()
    pen.color(color)
    pen.begin_fill()
    pen.circle(radius)
    pen.end_fill()

def dot(x, y, size, color):
    pen.penup()
    pen.goto(x, y)
    pen.color(color)
    pen.dot(size)

def rect(x, y, width, height, color):
    pen.penup()
    pen.goto(x, y)
    pen.setheading(0)
    pen.pendown()
    pen.color(color)
    pen.begin_fill()
    for length in [width, height, width, height]:
        pen.forward(length)
        pen.left(90)
    pen.end_fill()

# Add a triangle(x, y, size, color) helper

circle(0, 0, 80, 'yellow')
dot(-30, 20, 15, 'black')
dot(30, 20, 15, 'black')
rect(-25, -30, 50, 15, 'red')
# Add a triangle() call for the nose

screen.mainloop()

Tap ▶ Run. The face now has eyes, mouth, AND a triangle nose. 👃

Next → Step 5

⬅ Back to Step 3


Adapted from Raspberry Pi Foundation — Make a Face under CC BY-SA 4.0.