Kodewick
Start learning →

Python Turtle Snowman

Three snowballs, smaller going up, with a hat and a carrot nose, and snow still falling.

Python Turtle Snowman
The full code (61 lines)
import turtle
import random

screen = turtle.Screen()
screen.bgcolor("#16325c")
t = turtle.Turtle()
t.hideturtle()
t.speed(0)
t.penup()

# snow on the ground
t.goto(-320, -200)
t.color("white")
t.begin_fill()
for x, y in [(320, -200), (320, -320), (-320, -320)]:
    t.goto(x, y)
t.end_fill()

# the body: three snowballs, smaller going up
t.goto(0, -130)
t.dot(200, "white")
t.goto(0, 10)
t.dot(150, "white")
t.goto(0, 120)
t.dot(110, "white")

# eyes and buttons
for x, y, size in [(-18, 135, 12), (18, 135, 12), (0, 40, 12), (0, 10, 12), (0, -20, 12)]:
    t.goto(x, y)
    t.dot(size, "black")

# a carrot nose
t.goto(0, 120)
t.color("orange")
t.begin_fill()
t.goto(45, 112)
t.goto(0, 108)
t.end_fill()

# arms
t.pencolor("saddlebrown")
t.pensize(5)
for sx in [-1, 1]:
    t.goto(sx * 65, 30)
    t.pendown()
    t.goto(sx * 140, 80)
    t.penup()

# the hat
t.pensize(1)
t.goto(-60, 165)
t.color("black")
t.begin_fill()
for x, y in [(60, 165), (60, 175), (35, 175), (35, 235), (-35, 235), (-35, 175), (-60, 175)]:
    t.goto(x, y)
t.end_fill()

# snowflakes
for i in range(90):
    t.goto(random.randint(-300, 300), random.randint(-180, 300))
    t.dot(random.randint(3, 7), "white")

How it is drawn

Each snowball is t.dot(diameter, color): go to its centre and put down a big dot. Each centre is higher and each dot smaller.

The eyes and buttons are a list of (x, y, size), drawn by one loop.

The nose, the hat and the ground are shapes walked point by point with goto, filled by begin_fill() and end_fill().

The arms: for sx in [-1, 1] — x times -1 is the left arm, times 1 the right one: one piece of code, two mirrored arms.

Questions

Why penup at the start?

Almost everything here is dots and fills, so the turtle should not leave lines as it moves; only the arms put the pen down for a moment.

How do I give it a scarf?

Click Edit and, before the hat, walk a red strip around (-55, 70) between begin_fill and end_fill.

Try another