python 绘制小猪佩奇
一、预期结果
二、核心代码
import turtle
print("开始绘制小猪佩奇")
pen = turtle.Turtle()
pen.pensize(4)
#pen.hideturtle()
pen.speed(1000)
pen.color("#ff9bc0","pink")
pen.setheading(-30)
pen.pu()
pen.goto(-100,100)
pen.begin_fill()
pen.pd()
a=0.4
print("绘制鼻子")
for i in range(120):
if 0<=i<30 or 60<=i<90:
a=a+0.08
pen.lt(3)
pen.fd(a)
else:
a=a-0.08
pen.lt(3)
pen.fd(a)
pen.end_fill()
pen.pu()
pen.seth(90)
pen.fd(25)
pen.setheading(0)
pen.fd(10)
pen.begin_fill()
pen.pd()
pen.circle(5)
pen.color("#A0522D")
pen.end_fill()
pen.pu()
pen.seth(0)
pen.fd(20)
pen.pd()
pen.pencolor("#ff9bc0")
pen.begin_fill()
pen.circle(5)
pen.color("#A0522D")
pen.end_fill()
print("绘制头部")
pen.color("#ff9bc0","pink")
pen.pu()
pen.seth(90)
pen.fd(41)
pen.seth(0)
pen.pd()
pen.begin_fill()
pen.seth(0)
pen.circle(-300,30)
pen.circle(-100,60)
pen.circle(-80,100)
pen.circle(-150,20)
pen.circle(-60,95)
pen.seth(161)
pen.circle(-300,15)
pen.pu()
pen.goto(-100,100)
pen.pd()
pen.seth(-30)
a=0.4
for i in range(60):
if 0<=i<30:
a=a+0.08
pen.lt(3)
pen.fd(a)
else:
a=a-0.08
pen.lt(3)
pen.fd(a)
pen.end_fill()
print("绘制耳朵")
pen.color("#ff9bc0","pink")
pen.pu()
pen.seth(90)
pen.fd(-7)
pen.seth(0)
pen.fd(70)
pen.pd()
pen.begin_fill()
pen.seth(100)
pen.circle(-50,50)
pen.circle(-10,120)
pen.circle(-50,54)
pen.end_fill()
pen.pu()
pen.seth(90)
pen.fd(-12)
pen.seth(0)
pen.fd(30)
pen.pd()
pen.begin_fill()
pen.seth(100)
pen.circle(-50,50)
pen.circle(-10,120)
pen.circle(-50,56)
pen.end_fill()
pen.color("#ff9bc0","white")
pen.pu()
print("绘制眼睛")
pen.seth(90)
pen.fd(-20)
pen.seth(0)
pen.fd(-95)
pen.pd()
pen.begin_fill()
pen.circle(15)
pen.end_fill()
pen.color("black")
pen.pu()
pen.seth(90)
pen.fd(12)
pen.seth(0)
pen.fd(-3)
pen.pd()
pen.begin_fill()
pen.circle(3)
pen.end_fill()
pen.color("#ff9bc0","white")
pen.pu()
pen.seth(90)
pen.fd(-25)
pen.seth(0)
pen.fd(40)
pen.pd()
pen.begin_fill()
pen.circle(15)
pen.end_fill()
pen.color("black")
pen.pu()
pen.seth(90)
pen.fd(12)
pen.seth(0)
pen.fd(-3)
pen.pd()
pen.begin_fill()
pen.circle(3)
pen.end_fill()
print("绘制脸")
pen.color("#ff9bc0")
pen.pu()
pen.seth(90)
pen.fd(-95)
pen.seth(0)
pen.fd(65)
pen.pd()
pen.begin_fill()
pen.circle(30)
pen.end_fill()
print("绘制嘴巴")
pen.color("#EF4513")
pen.pu()
pen.seth(90)
pen.fd(15)
pen.seth(0)
pen.fd(-100)
pen.pd()
pen.seth(-80)
pen.circle(30,40)
pen.circle(40,80)
print("绘制身体")
pen.color("red","#FF6347")
pen.pu()
pen.seth(90)
pen.fd(-20)
pen.seth(0)
pen.fd(-78)
pen.pd()
pen.begin_fill()
pen.seth(-130)
pen.circle(100,10)
pen.circle(300,30)
pen.seth(0)
pen.fd(230)
pen.seth(90)
pen.circle(300,30)
pen.circle(100,3)
pen.color("#FF9BC0","#FF6464")
pen.seth(-135)
pen.circle(-80,63)
pen.circle(-150,24)
pen.end_fill()
print("绘制胳膊")
pen.color("#FF9BC0")
pen.pu()
pen.seth(90)
pen.fd(-40)
pen.seth(0)
pen.fd(-27)
pen.pd()
pen.seth(-160)
pen.circle(300,15)
pen.pu()
pen.seth(90)
pen.fd(15)
pen.seth(0)
pen.fd(0)
pen.pd()
pen.seth(-10)
pen.circle(-20,90)
pen.pu()
pen.seth(90)
pen.fd(30)
pen.seth(0)
pen.fd(237)
pen.pd()
pen.seth(-20)
pen.circle(-300,15)
pen.pu()
pen.seth(90)
pen.fd(20)
pen.seth(0)
pen.fd(0)
pen.pd()
pen.seth(-170)
pen.circle(20,90)
print("绘制腿和脚")
pen.pensize(10)
pen.color("#F08080")
pen.pu()
pen.seth(90)
pen.fd(-75)
pen.seth(0)
pen.fd(-180)
pen.pd()
pen.seth(-90)
pen.fd(40)
pen.seth(-180)
pen.color("black")
pen.pensize(15)
pen.fd(20)
pen.pensize(10)
pen.color("#F08080")
pen.pu()
pen.seth(90)
pen.fd(40)
pen.seth(0)
pen.fd(90)
pen.pd()
pen.seth(-90)
pen.fd(40)
pen.seth(-180)
pen.color("black")
pen.pensize(15)
pen.fd(20)
print("绘制尾巴")
pen.pensize(4)
pen.color("#FF9BC0")
pen.pu()
pen.seth(90)
pen.fd(70)
pen.seth(0)
pen.fd(95)
pen.pd()
pen.seth(0)
pen.circle(70,20)
pen.circle(10,330)
pen.circle(70,30)
# pen.mainloop()
# 隐藏画笔
pen.hideturtle()
print("绘制完成")
turtle.done()