Nanfeng

Notes on software development, code, and curious ideas

Drawing a Brown Bear with Python Turtle

After sharing a video of this Turtle drawing, several people asked for the code. It uses only Python’s standard turtle module.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from turtle import *

hideturtle()
setup(400, 800)
speed(0)
pensize(3)
pencolor("black")

# Head
penup()
goto(0, 100)
pendown()
fillcolor("brown")
begin_fill()
circle(100)
end_fill()

# White muzzle
penup()
goto(0, 150)
pendown()
pencolor("white")
fillcolor("white")
begin_fill()
circle(30)
end_fill()

# Eyes
pencolor("black")
for x in (-25, 25):
penup()
goto(x, 203)
pendown()
fillcolor("black")
begin_fill()
circle(10)
end_fill()

# Nose and mouth
penup()
goto(0, 180)
pendown()
begin_fill()
circle(6)
end_fill()

pensize(5)
for heading in (-135, -45):
penup()
goto(0, 180)
setheading(heading)
pendown()
forward(12)

# Ears
pensize(3)
for heading, radius in ((30, 30), (150, -30)):
penup()
goto(0, 200)
setheading(heading)
forward(100)
pendown()
fillcolor("brown")
begin_fill()
circle(radius, 215)
end_fill()

# Body
penup()
goto(0, 80)
setheading(0)
pendown()
fillcolor("black")
begin_fill()
circle(-40)
end_fill()

done()

The coordinates can be adjusted to refine the proportions. Turtle is normally included with desktop Python, but it requires a working Tk installation and a graphical environment.

+