使用python turtle库绘制佩奇
import turtle as t
t.pensize(3)
t.colormode(255)
t.setup(800, 800)
t.speed(10)
#身体
t.color("pink", "red")
t.pu()
t.goto(0,-10)
t.pendown()
t.begin_fill()
t.setheading(230)
t.fd(200)
t.setheading(0)
t.fd(400)
t.setheading(135)
t.fd(230)
t.end_fill()
#头
t.color("red", "pink")
t.pu()
t.goto(-200,200)
t.setheading(0)
t.pendown()
t.begin_fill()
t.setheading(350)
t.circle(-300,30)
t.setheading(230)
t.circle(80,100)
t.circle(280,10)
t.circle(120,180)
t.setheading(145)
t.circle(300,51)
t.end_fill()
#耳朵
t.pu()
t.goto(100,212)
t.pd()
t.setheading(-30)
t.begin_fill() # 准备开始填充图形
a = 0.9
for i in range(60):
if 0 <= i < 15 or 30 <= i < 45:
a = a + 0.08
t.left(7) # 向左转3度
t.forward(a) # 向前走a的步长
else:
a = a - 0.08
t.left(3)
t.forward(a)
t.end_fill() # 填充完成
t.pu()
t.goto(50,238)
t.pd()
t.setheading(-30)
t.begin_fill() # 准备开始填充图形
a = 0.9
for i in range(60):
if 0 <= i < 15 or 30 <= i < 45:
a = a + 0.08
t.left(7) # 向左转3度
t.forward(a) # 向前走a的步长
else:
a = a - 0.08
t.left(3)
t.forward(a)
t.end_fill() # 填充完成
#鼻子
t.pu()
t.goto(-200,200)
t.pd()
t.setheading(-30)
t.begin_fill() # 准备开始填充图形
a = 0.4
for i in range(120):
if 0 <= i < 30 or 60 <= i < 90:
a = a + 0.08
t.left(3) # 向左转3度
t.forward(a) # 向前走a的步长
else:
a = a - 0.08
t.left(3)
t.forward(a)
t.end_fill() # 填充完成
t.pu()
t.goto(-175,220)
t.pd()
t.circle(5)
t.pu()
t.goto(-190,230)
t.pd()
t.circle(5)
#嘴
t.pu()
t.goto(-20,50)
t.setheading(300)
t.pendown()
t.circle(80,80)
#腮
t.pu()
t.goto(50,80)
t.setheading(300)
t.color("black", "grey")
t.pendown()
t.begin_fill()
t.circle(40)
t.end_fill()
#眼
t.color("black", "white")
t.pu()
t.goto(-50,220)
t.pendown()
t.begin_fill()
t.circle(10)
t.end_fill()
t.pu()
t.goto(-42,225)
t.pendown()
t.dot(10, "black")
t.pu()
t.goto(-90,228)
t.pendown()
t.begin_fill()
t.circle(10)
t.end_fill()
t.pu()
t.goto(-82,233)
t.pendown()
t.dot(10, "black")
#手
t.color("black")
t.pu()
t.goto(-18,-30)
t.setheading(170)
t.pendown()
t.circle(180,70)
t.pu()
t.goto(-195,-100)
t.setheading(180)
t.pendown()
t.fd(30)
t.pu()
t.goto(-195,-100)
t.setheading(330)
t.pendown()
t.fd(30)
t.pu()
t.goto(130,-30)
t.setheading(0)
t.pendown()
t.circle(-180,70)
t.pu()
t.goto(290,-130)
t.setheading(199)
t.pendown()
t.fd(30)
t.pu()
t.goto(290,-130)
t.setheading(330)
t.pendown()
t.fd(30)
#腿
t.color("black", "white")
t.pu()
t.goto(90,-160)
t.pendown()
t.setheading(270)
t.fd(100)
t.setheading(0)
t.fd(10)
t.setheading(90)
t.fd(100)
t.color("white", "black")
t.pu()
t.goto(100,-260)
t.begin_fill()
t.setheading(180)
t.fd(30)
t.setheading(90)
t.fd(10)
t.setheading(0)
t.fd(30)
t.end_fill()
t.color("black", "white")
t.pu()
t.goto(40,-160)
t.pendown()
t.setheading(270)
t.fd(100)
t.setheading(0)
t.fd(10)
t.setheading(90)
t.fd(100)
t.color("white", "black")
t.pu()
t.goto(50,-260)
t.begin_fill()
t.setheading(180)
t.fd(30)
t.setheading(90)
t.fd(10)
t.setheading(0)
t.fd(30)
t.end_fill()
t.done()
存在问题:
使用end_fill()时,总是覆盖已存在的图案。
所以只能调整绘制顺序,以避免覆盖。